1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_ANDROID_TAB_WEB_CONTENTS_DELEGATE_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_TAB_WEB_CONTENTS_DELEGATE_ANDROID_H_
7 
8 #include <memory>
9 
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "base/scoped_observer.h"
13 #include "components/embedder_support/android/delegate/web_contents_delegate_android.h"
14 #include "components/find_in_page/find_result_observer.h"
15 #include "components/find_in_page/find_tab_helper.h"
16 #include "components/paint_preview/buildflags/buildflags.h"
17 #include "printing/buildflags/buildflags.h"
18 #include "third_party/blink/public/mojom/frame/blocked_navigation_types.mojom.h"
19 
20 namespace content {
21 struct FileChooserParams;
22 class WebContents;
23 }
24 
25 namespace gfx {
26 class Rect;
27 class RectF;
28 }
29 
30 namespace url {
31 class Origin;
32 }
33 
34 namespace android {
35 
36 // Chromium Android specific WebContentsDelegate.
37 // Should contain any WebContentsDelegate implementations required by
38 // the Chromium Android port but not to be shared with WebView.
39 class TabWebContentsDelegateAndroid
40     : public web_contents_delegate_android::WebContentsDelegateAndroid,
41       public find_in_page::FindResultObserver {
42  public:
43   TabWebContentsDelegateAndroid(JNIEnv* env, jobject obj);
44   ~TabWebContentsDelegateAndroid() override;
45 
46   void PortalWebContentsCreated(content::WebContents* portal_contents) override;
47   void RunFileChooser(content::RenderFrameHost* render_frame_host,
48                       scoped_refptr<content::FileSelectListener> listener,
49                       const blink::mojom::FileChooserParams& params) override;
50   void CreateSmsPrompt(content::RenderFrameHost*,
51                        const url::Origin&,
52                        const std::string& one_time_code,
53                        base::OnceClosure on_confirm,
54                        base::OnceClosure on_cancel) override;
55   bool ShouldFocusLocationBarByDefault(content::WebContents* source) override;
56   blink::mojom::DisplayMode GetDisplayMode(
57       const content::WebContents* web_contents) override;
58   void FindReply(content::WebContents* web_contents,
59                  int request_id,
60                  int number_of_matches,
61                  const gfx::Rect& selection_rect,
62                  int active_match_ordinal,
63                  bool final_update) override;
64   void FindMatchRectsReply(content::WebContents* web_contents,
65                            int version,
66                            const std::vector<gfx::RectF>& rects,
67                            const gfx::RectF& active_rect) override;
68   content::JavaScriptDialogManager* GetJavaScriptDialogManager(
69       content::WebContents* source) override;
70   void AdjustPreviewsStateForNavigation(
71       content::WebContents* web_contents,
72       blink::PreviewsState* previews_state) override;
73   void RequestMediaAccessPermission(
74       content::WebContents* web_contents,
75       const content::MediaStreamRequest& request,
76       content::MediaResponseCallback callback) override;
77   bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
78                                   const GURL& security_origin,
79                                   blink::mojom::MediaStreamType type) override;
80   void SetOverlayMode(bool use_overlay_mode) override;
81   void RequestPpapiBrokerPermission(
82       content::WebContents* web_contents,
83       const GURL& url,
84       const base::FilePath& plugin_path,
85       base::OnceCallback<void(bool)> callback) override;
86   content::WebContents* OpenURLFromTab(
87       content::WebContents* source,
88       const content::OpenURLParams& params) override;
89   bool ShouldResumeRequestsForCreatedWindow() override;
90   void AddNewContents(content::WebContents* source,
91                       std::unique_ptr<content::WebContents> new_contents,
92                       const GURL& target_url,
93                       WindowOpenDisposition disposition,
94                       const gfx::Rect& initial_rect,
95                       bool user_gesture,
96                       bool* was_blocked) override;
97   blink::SecurityStyle GetSecurityStyle(
98       content::WebContents* web_contents,
99       content::SecurityStyleExplanations* security_style_explanations) override;
100   void OnDidBlockNavigation(
101       content::WebContents* web_contents,
102       const GURL& blocked_url,
103       const GURL& initiator_url,
104       blink::mojom::NavigationBlockedReason reason) override;
105   void UpdateUserGestureCarryoverInfo(
106       content::WebContents* web_contents) override;
107   content::PictureInPictureResult EnterPictureInPicture(
108       content::WebContents* web_contents,
109       const viz::SurfaceId&,
110       const gfx::Size&) override;
111   void ExitPictureInPicture() override;
112   std::unique_ptr<content::WebContents> ActivatePortalWebContents(
113       content::WebContents* predecessor_contents,
114       std::unique_ptr<content::WebContents> portal_contents) override;
115   device::mojom::GeolocationContext* GetInstalledWebappGeolocationContext()
116       override;
117 
118 #if BUILDFLAG(ENABLE_PRINTING)
119   void PrintCrossProcessSubframe(
120       content::WebContents* web_contents,
121       const gfx::Rect& rect,
122       int document_cookie,
123       content::RenderFrameHost* subframe_host) const override;
124 #endif
125 
126 #if BUILDFLAG(ENABLE_PAINT_PREVIEW)
127   void CapturePaintPreviewOfSubframe(
128       content::WebContents* web_contents,
129       const gfx::Rect& rect,
130       const base::UnguessableToken& guid,
131       content::RenderFrameHost* render_frame_host) override;
132 #endif
133 
134   // find_in_page::FindResultObserver:
135   void OnFindResultAvailable(content::WebContents* web_contents) override;
136   void OnFindTabHelperDestroyed(find_in_page::FindTabHelper* helper) override;
137 
138   bool ShouldEnableEmbeddedMediaExperience() const;
139   bool IsPictureInPictureEnabled() const;
140   bool IsNightModeEnabled() const;
141   bool CanShowAppBanners() const;
142 
143   // Returns true if this tab is currently presented in the context of custom
144   // tabs. Tabs can be moved between different activities so the returned value
145   // might change over the lifetime of the tab.
146   bool IsCustomTab() const;
147   const GURL GetManifestScope() const;
148   bool IsInstalledWebappDelegateGeolocation() const;
149 
150  private:
151   std::unique_ptr<device::mojom::GeolocationContext>
152       installed_webapp_geolocation_context_;
153 
154   ScopedObserver<find_in_page::FindTabHelper, find_in_page::FindResultObserver>
155       find_result_observer_{this};
156 
157   DISALLOW_COPY_AND_ASSIGN(TabWebContentsDelegateAndroid);
158 };
159 
160 }  // namespace android
161 
162 #endif  // CHROME_BROWSER_ANDROID_TAB_WEB_CONTENTS_DELEGATE_ANDROID_H_
163