OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
12 #include "chrome/browser/guest_view/guest_view.h" | 12 #include "chrome/browser/guest_view/guest_view.h" |
13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" | 13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" |
14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" | 14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" |
| 15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
15 #include "chrome/common/extensions/api/webview.h" | 16 #include "chrome/common/extensions/api/webview.h" |
16 #include "content/public/browser/javascript_dialog_manager.h" | 17 #include "content/public/browser/javascript_dialog_manager.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
19 #include "third_party/WebKit/public/web/WebFindOptions.h" | 20 #include "third_party/WebKit/public/web/WebFindOptions.h" |
20 | 21 |
21 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 23 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
23 #endif | 24 #endif |
24 | 25 |
(...skipping 14 matching lines...) Expand all Loading... |
39 // <webview> tag. It provides the browser-side implementation of the <webview> | 40 // <webview> tag. It provides the browser-side implementation of the <webview> |
40 // API and manages the lifetime of <webview> extension events. WebViewGuest is | 41 // API and manages the lifetime of <webview> extension events. WebViewGuest is |
41 // created on attachment. That is, when a guest WebContents is associated with | 42 // created on attachment. That is, when a guest WebContents is associated with |
42 // a particular embedder WebContents. This happens on either initial navigation | 43 // a particular embedder WebContents. This happens on either initial navigation |
43 // or through the use of the New Window API, when a new window is attached to | 44 // or through the use of the New Window API, when a new window is attached to |
44 // a particular <webview>. | 45 // a particular <webview>. |
45 class WebViewGuest : public GuestView<WebViewGuest>, | 46 class WebViewGuest : public GuestView<WebViewGuest>, |
46 public content::NotificationObserver, | 47 public content::NotificationObserver, |
47 public content::WebContentsObserver { | 48 public content::WebContentsObserver { |
48 public: | 49 public: |
49 WebViewGuest(content::WebContents* guest_web_contents, | 50 WebViewGuest(int guest_instance_id, |
50 const std::string& embedder_extension_id, | 51 content::WebContents* guest_web_contents, |
51 const base::WeakPtr<GuestViewBase>& opener); | 52 const std::string& embedder_extension_id); |
52 | 53 |
53 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a | 54 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a |
54 // WebViewGuest. | 55 // WebViewGuest. |
55 static int GetViewInstanceId(content::WebContents* contents); | 56 static int GetViewInstanceId(content::WebContents* contents); |
56 static const char Type[]; | 57 static const char Type[]; |
57 | 58 |
58 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; | 59 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; |
59 // Shows the context menu for the guest. | 60 // Shows the context menu for the guest. |
60 // |items| acts as a filter. This restricts the current context's default | 61 // |items| acts as a filter. This restricts the current context's default |
61 // menu items to contain only the items from |items|. | 62 // menu items to contain only the items from |items|. |
(...skipping 19 matching lines...) Expand all Loading... |
81 virtual void EmbedderDestroyed() OVERRIDE; | 82 virtual void EmbedderDestroyed() OVERRIDE; |
82 virtual void FindReply(int request_id, | 83 virtual void FindReply(int request_id, |
83 int number_of_matches, | 84 int number_of_matches, |
84 const gfx::Rect& selection_rect, | 85 const gfx::Rect& selection_rect, |
85 int active_match_ordinal, | 86 int active_match_ordinal, |
86 bool final_update) OVERRIDE; | 87 bool final_update) OVERRIDE; |
87 virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE; | 88 virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE; |
88 virtual void HandleKeyboardEvent( | 89 virtual void HandleKeyboardEvent( |
89 const content::NativeWebKeyboardEvent& event) OVERRIDE; | 90 const content::NativeWebKeyboardEvent& event) OVERRIDE; |
90 virtual bool IsDragAndDropEnabled() OVERRIDE; | 91 virtual bool IsDragAndDropEnabled() OVERRIDE; |
91 virtual bool IsOverridingUserAgent() const OVERRIDE; | |
92 virtual void LoadAbort(bool is_top_level, | |
93 const GURL& url, | |
94 const std::string& error_type) OVERRIDE; | |
95 virtual void RendererResponsive() OVERRIDE; | 92 virtual void RendererResponsive() OVERRIDE; |
96 virtual void RendererUnresponsive() OVERRIDE; | 93 virtual void RendererUnresponsive() OVERRIDE; |
97 virtual void RequestPermission( | |
98 BrowserPluginPermissionType permission_type, | |
99 const base::DictionaryValue& request_info, | |
100 const PermissionResponseCallback& callback, | |
101 bool allowed_by_default) OVERRIDE; | |
102 virtual GURL ResolveURL(const std::string& src) OVERRIDE; | |
103 virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) | 94 virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) |
104 OVERRIDE; | 95 OVERRIDE; |
105 virtual void RequestMediaAccessPermission( | 96 virtual void RequestMediaAccessPermission( |
106 const content::MediaStreamRequest& request, | 97 const content::MediaStreamRequest& request, |
107 const content::MediaResponseCallback& callback) OVERRIDE; | 98 const content::MediaResponseCallback& callback) OVERRIDE; |
108 virtual void CanDownload(const std::string& request_method, | 99 virtual void CanDownload(const std::string& request_method, |
109 const GURL& url, | 100 const GURL& url, |
110 const base::Callback<void(bool)>& callback) OVERRIDE; | 101 const base::Callback<void(bool)>& callback) OVERRIDE; |
111 virtual void RequestPointerLockPermission( | 102 virtual void RequestPointerLockPermission( |
112 bool user_gesture, | 103 bool user_gesture, |
113 bool last_unlocked_by_target, | 104 bool last_unlocked_by_target, |
114 const base::Callback<void(bool)>& callback) OVERRIDE; | 105 const base::Callback<void(bool)>& callback) OVERRIDE; |
115 virtual content::JavaScriptDialogManager* | 106 virtual content::JavaScriptDialogManager* |
116 GetJavaScriptDialogManager() OVERRIDE; | 107 GetJavaScriptDialogManager() OVERRIDE; |
117 virtual content::ColorChooser* OpenColorChooser( | 108 virtual content::ColorChooser* OpenColorChooser( |
118 content::WebContents* web_contents, | 109 content::WebContents* web_contents, |
119 SkColor color, | 110 SkColor color, |
120 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; | 111 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; |
121 virtual void RunFileChooser( | 112 virtual void RunFileChooser( |
122 content::WebContents* web_contents, | 113 content::WebContents* web_contents, |
123 const content::FileChooserParams& params) OVERRIDE; | 114 const content::FileChooserParams& params) OVERRIDE; |
| 115 virtual void NavigateGuest(const std::string& src) OVERRIDE; |
| 116 virtual void Destroy() OVERRIDE; |
| 117 virtual void AddNewContents(content::WebContents* source, |
| 118 content::WebContents* new_contents, |
| 119 WindowOpenDisposition disposition, |
| 120 const gfx::Rect& initial_pos, |
| 121 bool user_gesture, |
| 122 bool* was_blocked) OVERRIDE; |
| 123 virtual content::WebContents* OpenURLFromTab( |
| 124 content::WebContents* source, |
| 125 const content::OpenURLParams& params) OVERRIDE; |
| 126 virtual void WebContentsCreated(content::WebContents* source_contents, |
| 127 int opener_render_frame_id, |
| 128 const base::string16& frame_name, |
| 129 const GURL& target_url, |
| 130 content::WebContents* new_contents) OVERRIDE; |
124 | 131 |
125 // NotificationObserver implementation. | 132 // NotificationObserver implementation. |
126 virtual void Observe(int type, | 133 virtual void Observe(int type, |
127 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
128 const content::NotificationDetails& details) OVERRIDE; | 135 const content::NotificationDetails& details) OVERRIDE; |
129 | 136 |
130 // Set the zoom factor. | 137 // Set the zoom factor. |
131 virtual void SetZoom(double zoom_factor) OVERRIDE; | 138 virtual void SetZoom(double zoom_factor) OVERRIDE; |
132 | 139 |
133 // Returns the current zoom factor. | 140 // Returns the current zoom factor. |
134 double GetZoom(); | 141 double GetZoom(); |
135 | 142 |
136 // Begin or continue a find request. | 143 // Begin or continue a find request. |
137 void Find(const base::string16& search_text, | 144 void Find(const base::string16& search_text, |
138 const blink::WebFindOptions& options, | 145 const blink::WebFindOptions& options, |
139 scoped_refptr<extensions::WebviewFindFunction> find_function); | 146 scoped_refptr<extensions::WebviewFindFunction> find_function); |
140 | 147 |
141 // Conclude a find request to clear highlighting. | 148 // Conclude a find request to clear highlighting. |
142 void StopFinding(content::StopFindAction); | 149 void StopFinding(content::StopFindAction); |
143 | 150 |
144 // If possible, navigate the guest to |relative_index| entries away from the | 151 // If possible, navigate the guest to |relative_index| entries away from the |
145 // current navigation entry. | 152 // current navigation entry. |
146 void Go(int relative_index); | 153 void Go(int relative_index); |
147 | 154 |
148 // Reload the guest. | 155 // Reload the guest. |
149 void Reload(); | 156 void Reload(); |
150 | 157 |
| 158 typedef base::Callback<void(bool /* allow */, |
| 159 const std::string& /* user_input */)> |
| 160 PermissionResponseCallback; |
| 161 int RequestPermission( |
| 162 WebViewPermissionType permission_type, |
| 163 const base::DictionaryValue& request_info, |
| 164 const PermissionResponseCallback& callback, |
| 165 bool allowed_by_default); |
| 166 |
151 // Requests Geolocation Permission from the embedder. | 167 // Requests Geolocation Permission from the embedder. |
152 void RequestGeolocationPermission(int bridge_id, | 168 void RequestGeolocationPermission(int bridge_id, |
153 const GURL& requesting_frame, | 169 const GURL& requesting_frame, |
154 bool user_gesture, | 170 bool user_gesture, |
155 const base::Callback<void(bool)>& callback); | 171 const base::Callback<void(bool)>& callback); |
156 | 172 |
157 void OnWebViewGeolocationPermissionResponse( | 173 void OnWebViewGeolocationPermissionResponse( |
158 int bridge_id, | 174 int bridge_id, |
159 bool user_gesture, | 175 bool user_gesture, |
160 const base::Callback<void(bool)>& callback, | 176 const base::Callback<void(bool)>& callback, |
(...skipping 11 matching lines...) Expand all Loading... |
172 void OnWebViewDownloadPermissionResponse( | 188 void OnWebViewDownloadPermissionResponse( |
173 const base::Callback<void(bool)>& callback, | 189 const base::Callback<void(bool)>& callback, |
174 bool allow, | 190 bool allow, |
175 const std::string& user_input); | 191 const std::string& user_input); |
176 | 192 |
177 void OnWebViewPointerLockPermissionResponse( | 193 void OnWebViewPointerLockPermissionResponse( |
178 const base::Callback<void(bool)>& callback, | 194 const base::Callback<void(bool)>& callback, |
179 bool allow, | 195 bool allow, |
180 const std::string& user_input); | 196 const std::string& user_input); |
181 | 197 |
| 198 void OnWebViewNewWindowResponse(int new_window_instance_id, |
| 199 bool allow, |
| 200 const std::string& user_input); |
| 201 |
182 enum PermissionResponseAction { | 202 enum PermissionResponseAction { |
183 DENY, | 203 DENY, |
184 ALLOW, | 204 ALLOW, |
185 DEFAULT | 205 DEFAULT |
186 }; | 206 }; |
187 | 207 |
188 enum SetPermissionResult { | 208 enum SetPermissionResult { |
189 SET_PERMISSION_INVALID, | 209 SET_PERMISSION_INVALID, |
190 SET_PERMISSION_ALLOWED, | 210 SET_PERMISSION_ALLOWED, |
191 SET_PERMISSION_DENIED | 211 SET_PERMISSION_DENIED |
(...skipping 27 matching lines...) Expand all Loading... |
219 extensions::ScriptExecutor* script_executor() { | 239 extensions::ScriptExecutor* script_executor() { |
220 return script_executor_.get(); | 240 return script_executor_.get(); |
221 } | 241 } |
222 | 242 |
223 private: | 243 private: |
224 virtual ~WebViewGuest(); | 244 virtual ~WebViewGuest(); |
225 | 245 |
226 // A map to store the callback for a request keyed by the request's id. | 246 // A map to store the callback for a request keyed by the request's id. |
227 struct PermissionResponseInfo { | 247 struct PermissionResponseInfo { |
228 PermissionResponseCallback callback; | 248 PermissionResponseCallback callback; |
229 BrowserPluginPermissionType permission_type; | 249 WebViewPermissionType permission_type; |
230 bool allowed_by_default; | 250 bool allowed_by_default; |
231 PermissionResponseInfo(); | 251 PermissionResponseInfo(); |
232 PermissionResponseInfo(const PermissionResponseCallback& callback, | 252 PermissionResponseInfo(const PermissionResponseCallback& callback, |
233 BrowserPluginPermissionType permission_type, | 253 WebViewPermissionType permission_type, |
234 bool allowed_by_default); | 254 bool allowed_by_default); |
235 ~PermissionResponseInfo(); | 255 ~PermissionResponseInfo(); |
236 }; | 256 }; |
237 | 257 |
238 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, | 258 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
239 bool allow); | 259 bool allow); |
240 | 260 |
241 // Returns the top level items (ignoring submenus) as Value. | 261 // Returns the top level items (ignoring submenus) as Value. |
242 static scoped_ptr<base::ListValue> MenuModelToValue( | 262 static scoped_ptr<base::ListValue> MenuModelToValue( |
243 const ui::SimpleMenuModel& menu_model); | 263 const ui::SimpleMenuModel& menu_model); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 const chromeos::AccessibilityStatusEventDetails& details); | 312 const chromeos::AccessibilityStatusEventDetails& details); |
293 #endif | 313 #endif |
294 | 314 |
295 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | 315 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
296 | 316 |
297 // Bridge IDs correspond to a geolocation request. This method will remove | 317 // Bridge IDs correspond to a geolocation request. This method will remove |
298 // the bookkeeping for a particular geolocation request associated with the | 318 // the bookkeeping for a particular geolocation request associated with the |
299 // provided |bridge_id|. It returns the request ID of the geolocation request. | 319 // provided |bridge_id|. It returns the request ID of the geolocation request. |
300 int RemoveBridgeID(int bridge_id); | 320 int RemoveBridgeID(int bridge_id); |
301 | 321 |
302 int RequestPermissionInternal( | 322 void LoadURLWithParams(const GURL& url, |
303 BrowserPluginPermissionType permission_type, | 323 const content::Referrer& referrer, |
304 const base::DictionaryValue& request_info, | 324 content::PageTransition transition_type, |
305 const PermissionResponseCallback& callback, | 325 content::WebContents* web_contents); |
306 bool allowed_by_default); | 326 |
| 327 void RequestNewWindowPermission( |
| 328 WindowOpenDisposition disposition, |
| 329 const gfx::Rect& initial_bounds, |
| 330 bool user_gesture, |
| 331 content::WebContents* new_contents); |
| 332 |
| 333 // Destroy unattached new windows that have been opened by this |
| 334 // WebViewGuest. |
| 335 void DestroyUnattachedWindows(); |
| 336 |
| 337 // Requests resolution of a potentially relative URL. |
| 338 GURL ResolveURL(const std::string& src); |
| 339 |
| 340 // Notification that a load in the guest resulted in abort. Note that |url| |
| 341 // may be invalid. |
| 342 void LoadAbort(bool is_top_level, |
| 343 const GURL& url, |
| 344 const std::string& error_type); |
| 345 |
| 346 |
| 347 // Creates a new guest window owned by this WebViewGuest. |
| 348 WebViewGuest* CreateNewGuestWindow(const content::OpenURLParams& params); |
307 | 349 |
308 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); | 350 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); |
309 | 351 |
310 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 352 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
311 script_observers_; | 353 script_observers_; |
312 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 354 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
313 | 355 |
314 content::NotificationRegistrar notification_registrar_; | 356 content::NotificationRegistrar notification_registrar_; |
315 | 357 |
316 // A counter to generate a unique request id for a context menu request. | 358 // A counter to generate a unique request id for a context menu request. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 scoped_ptr<RenderViewContextMenu> pending_menu_; | 396 scoped_ptr<RenderViewContextMenu> pending_menu_; |
355 | 397 |
356 #if defined(OS_CHROMEOS) | 398 #if defined(OS_CHROMEOS) |
357 // Subscription to receive notifications on changes to a11y settings. | 399 // Subscription to receive notifications on changes to a11y settings. |
358 scoped_ptr<chromeos::AccessibilityStatusSubscription> | 400 scoped_ptr<chromeos::AccessibilityStatusSubscription> |
359 accessibility_subscription_; | 401 accessibility_subscription_; |
360 #endif | 402 #endif |
361 | 403 |
362 std::map<int, int> bridge_id_to_request_id_map_; | 404 std::map<int, int> bridge_id_to_request_id_map_; |
363 | 405 |
| 406 // Tracks the name, and target URL of the new window. Once the first |
| 407 // navigation commits, we no longer track this information. |
| 408 struct NewWindowInfo { |
| 409 GURL url; |
| 410 std::string name; |
| 411 NewWindowInfo(const GURL& url, const std::string& name) : |
| 412 url(url), |
| 413 name(name) {} |
| 414 }; |
| 415 |
| 416 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
| 417 PendingWindowMap pending_new_windows_; |
| 418 |
364 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 419 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
365 }; | 420 }; |
366 | 421 |
367 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 422 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
OLD | NEW |