Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 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(content::WebContents* guest_web_contents, |
| 50 const std::string& embedder_extension_id, | 51 const std::string& embedder_extension_id); |
| 51 const base::WeakPtr<GuestViewBase>& opener); | |
| 52 | 52 |
| 53 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a | 53 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a |
| 54 // WebViewGuest. | 54 // WebViewGuest. |
| 55 static int GetViewInstanceId(content::WebContents* contents); | 55 static int GetViewInstanceId(content::WebContents* contents); |
| 56 static const char Type[]; | 56 static const char Type[]; |
| 57 | 57 |
| 58 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; | 58 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; |
| 59 // Shows the context menu for the guest. | 59 // Shows the context menu for the guest. |
| 60 // |items| acts as a filter. This restricts the current context's default | 60 // |items| acts as a filter. This restricts the current context's default |
| 61 // menu items to contain only the items from |items|. | 61 // menu items to contain only the items from |items|. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 82 virtual void FindReply(int request_id, | 82 virtual void FindReply(int request_id, |
| 83 int number_of_matches, | 83 int number_of_matches, |
| 84 const gfx::Rect& selection_rect, | 84 const gfx::Rect& selection_rect, |
| 85 int active_match_ordinal, | 85 int active_match_ordinal, |
| 86 bool final_update) OVERRIDE; | 86 bool final_update) OVERRIDE; |
| 87 virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE; | 87 virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE; |
| 88 virtual bool HandleKeyboardEvent( | 88 virtual bool HandleKeyboardEvent( |
| 89 const content::NativeWebKeyboardEvent& event) OVERRIDE; | 89 const content::NativeWebKeyboardEvent& event) OVERRIDE; |
| 90 virtual bool IsDragAndDropEnabled() OVERRIDE; | 90 virtual bool IsDragAndDropEnabled() OVERRIDE; |
| 91 virtual bool IsOverridingUserAgent() const 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; |
| 108 virtual void NavigateGuest(const std::string& src) OVERRIDE; | |
| 109 virtual void Destroy() OVERRIDE; | |
| 110 virtual void AddNewContents(content::WebContents* source, | |
| 111 content::WebContents* new_contents, | |
| 112 WindowOpenDisposition disposition, | |
| 113 const gfx::Rect& initial_pos, | |
| 114 bool user_gesture, | |
| 115 bool* was_blocked) OVERRIDE; | |
| 116 virtual content::WebContents* OpenURLFromTab( | |
| 117 content::WebContents* source, | |
| 118 const content::OpenURLParams& params) OVERRIDE; | |
| 119 virtual void WebContentsCreated(content::WebContents* source_contents, | |
| 120 int opener_render_frame_id, | |
| 121 const base::string16& frame_name, | |
| 122 const GURL& target_url, | |
| 123 content::WebContents* new_contents) OVERRIDE; | |
| 117 | 124 |
| 118 // NotificationObserver implementation. | 125 // NotificationObserver implementation. |
| 119 virtual void Observe(int type, | 126 virtual void Observe(int type, |
| 120 const content::NotificationSource& source, | 127 const content::NotificationSource& source, |
| 121 const content::NotificationDetails& details) OVERRIDE; | 128 const content::NotificationDetails& details) OVERRIDE; |
| 122 | 129 |
| 123 // Set the zoom factor. | 130 // Set the zoom factor. |
| 124 virtual void SetZoom(double zoom_factor) OVERRIDE; | 131 virtual void SetZoom(double zoom_factor) OVERRIDE; |
| 125 | 132 |
| 126 // Returns the current zoom factor. | 133 // Returns the current zoom factor. |
| 127 double GetZoom(); | 134 double GetZoom(); |
| 128 | 135 |
| 129 // Begin or continue a find request. | 136 // Begin or continue a find request. |
| 130 void Find(const base::string16& search_text, | 137 void Find(const base::string16& search_text, |
| 131 const blink::WebFindOptions& options, | 138 const blink::WebFindOptions& options, |
| 132 scoped_refptr<extensions::WebviewFindFunction> find_function); | 139 scoped_refptr<extensions::WebviewFindFunction> find_function); |
| 133 | 140 |
| 134 // Conclude a find request to clear highlighting. | 141 // Conclude a find request to clear highlighting. |
| 135 void StopFinding(content::StopFindAction); | 142 void StopFinding(content::StopFindAction); |
| 136 | 143 |
| 137 // If possible, navigate the guest to |relative_index| entries away from the | 144 // If possible, navigate the guest to |relative_index| entries away from the |
| 138 // current navigation entry. | 145 // current navigation entry. |
| 139 void Go(int relative_index); | 146 void Go(int relative_index); |
| 140 | 147 |
| 141 // Reload the guest. | 148 // Reload the guest. |
| 142 void Reload(); | 149 void Reload(); |
| 143 | 150 |
| 151 typedef base::Callback<void(bool /* allow */, | |
| 152 const std::string& /* user_input */)> | |
| 153 PermissionResponseCallback; | |
| 154 int RequestPermission( | |
| 155 WebViewPermissionType permission_type, | |
| 156 const base::DictionaryValue& request_info, | |
| 157 const PermissionResponseCallback& callback, | |
| 158 bool allowed_by_default); | |
| 159 | |
| 144 // Requests Geolocation Permission from the embedder. | 160 // Requests Geolocation Permission from the embedder. |
| 145 void RequestGeolocationPermission(int bridge_id, | 161 void RequestGeolocationPermission(int bridge_id, |
| 146 const GURL& requesting_frame, | 162 const GURL& requesting_frame, |
| 147 bool user_gesture, | 163 bool user_gesture, |
| 148 const base::Callback<void(bool)>& callback); | 164 const base::Callback<void(bool)>& callback); |
| 149 | 165 |
| 150 void OnWebViewGeolocationPermissionResponse( | 166 void OnWebViewGeolocationPermissionResponse( |
| 151 int bridge_id, | 167 int bridge_id, |
| 152 bool user_gesture, | 168 bool user_gesture, |
| 153 const base::Callback<void(bool)>& callback, | 169 const base::Callback<void(bool)>& callback, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 165 void OnWebViewDownloadPermissionResponse( | 181 void OnWebViewDownloadPermissionResponse( |
| 166 const base::Callback<void(bool)>& callback, | 182 const base::Callback<void(bool)>& callback, |
| 167 bool allow, | 183 bool allow, |
| 168 const std::string& user_input); | 184 const std::string& user_input); |
| 169 | 185 |
| 170 void OnWebViewPointerLockPermissionResponse( | 186 void OnWebViewPointerLockPermissionResponse( |
| 171 const base::Callback<void(bool)>& callback, | 187 const base::Callback<void(bool)>& callback, |
| 172 bool allow, | 188 bool allow, |
| 173 const std::string& user_input); | 189 const std::string& user_input); |
| 174 | 190 |
| 191 void OnWebViewNewWindowResponse( | |
| 192 int new_window_instance_id, | |
|
lazyboy
2014/05/12 23:00:20
Can fit in previous line, indentation is off.
Fady Samuel
2014/05/13 18:59:02
Done.
| |
| 193 bool allow, | |
| 194 const std::string& user_input); | |
| 195 | |
| 175 enum PermissionResponseAction { | 196 enum PermissionResponseAction { |
| 176 DENY, | 197 DENY, |
| 177 ALLOW, | 198 ALLOW, |
| 178 DEFAULT | 199 DEFAULT |
| 179 }; | 200 }; |
| 180 | 201 |
| 181 enum SetPermissionResult { | 202 enum SetPermissionResult { |
| 182 SET_PERMISSION_INVALID, | 203 SET_PERMISSION_INVALID, |
| 183 SET_PERMISSION_ALLOWED, | 204 SET_PERMISSION_ALLOWED, |
| 184 SET_PERMISSION_DENIED | 205 SET_PERMISSION_DENIED |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 212 extensions::ScriptExecutor* script_executor() { | 233 extensions::ScriptExecutor* script_executor() { |
| 213 return script_executor_.get(); | 234 return script_executor_.get(); |
| 214 } | 235 } |
| 215 | 236 |
| 216 private: | 237 private: |
| 217 virtual ~WebViewGuest(); | 238 virtual ~WebViewGuest(); |
| 218 | 239 |
| 219 // A map to store the callback for a request keyed by the request's id. | 240 // A map to store the callback for a request keyed by the request's id. |
| 220 struct PermissionResponseInfo { | 241 struct PermissionResponseInfo { |
| 221 PermissionResponseCallback callback; | 242 PermissionResponseCallback callback; |
| 222 BrowserPluginPermissionType permission_type; | 243 WebViewPermissionType permission_type; |
| 223 bool allowed_by_default; | 244 bool allowed_by_default; |
| 224 PermissionResponseInfo(); | 245 PermissionResponseInfo(); |
| 225 PermissionResponseInfo(const PermissionResponseCallback& callback, | 246 PermissionResponseInfo(const PermissionResponseCallback& callback, |
| 226 BrowserPluginPermissionType permission_type, | 247 WebViewPermissionType permission_type, |
| 227 bool allowed_by_default); | 248 bool allowed_by_default); |
| 228 ~PermissionResponseInfo(); | 249 ~PermissionResponseInfo(); |
| 229 }; | 250 }; |
| 230 | 251 |
| 231 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, | 252 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
| 232 bool allow); | 253 bool allow); |
| 233 | 254 |
| 234 // Returns the top level items (ignoring submenus) as Value. | 255 // Returns the top level items (ignoring submenus) as Value. |
| 235 static scoped_ptr<base::ListValue> MenuModelToValue( | 256 static scoped_ptr<base::ListValue> MenuModelToValue( |
| 236 const ui::SimpleMenuModel& menu_model); | 257 const ui::SimpleMenuModel& menu_model); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 const chromeos::AccessibilityStatusEventDetails& details); | 306 const chromeos::AccessibilityStatusEventDetails& details); |
| 286 #endif | 307 #endif |
| 287 | 308 |
| 288 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | 309 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
| 289 | 310 |
| 290 // Bridge IDs correspond to a geolocation request. This method will remove | 311 // Bridge IDs correspond to a geolocation request. This method will remove |
| 291 // the bookkeeping for a particular geolocation request associated with the | 312 // the bookkeeping for a particular geolocation request associated with the |
| 292 // provided |bridge_id|. It returns the request ID of the geolocation request. | 313 // provided |bridge_id|. It returns the request ID of the geolocation request. |
| 293 int RemoveBridgeID(int bridge_id); | 314 int RemoveBridgeID(int bridge_id); |
| 294 | 315 |
| 295 int RequestPermissionInternal( | 316 void LoadURLWithParams(const GURL& url, |
| 296 BrowserPluginPermissionType permission_type, | 317 const content::Referrer& referrer, |
| 297 const base::DictionaryValue& request_info, | 318 content::PageTransition transition_type, |
| 298 const PermissionResponseCallback& callback, | 319 content::WebContents* web_contents); |
| 299 bool allowed_by_default); | 320 |
| 321 void RequestNewWindowPermission( | |
| 322 WindowOpenDisposition disposition, | |
| 323 const gfx::Rect& initial_bounds, | |
| 324 bool user_gesture, | |
| 325 content::WebContents* new_contents); | |
| 326 | |
| 327 // Destroy unattached new windows that have been opened by this | |
| 328 // WebViewGuest. | |
| 329 void DestroyUnattachedWindows(); | |
| 330 | |
| 331 // Requests resolution of a potentially relative URL. | |
| 332 GURL ResolveURL(const std::string& src); | |
| 333 | |
| 334 // Notification that a load in the guest resulted in abort. Note that |url| | |
| 335 // may be invalid. | |
| 336 void LoadAbort(bool is_top_level, | |
| 337 const GURL& url, | |
| 338 const std::string& error_type); | |
| 339 | |
| 340 | |
| 341 // Creates a new guest window owned by this WebViewGuest | |
| 342 // BrowserPluginGuest. | |
| 343 WebViewGuest* CreateNewGuestWindow(const content::OpenURLParams& params); | |
| 300 | 344 |
| 301 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 345 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
| 302 script_observers_; | 346 script_observers_; |
| 303 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 347 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
| 304 | 348 |
| 305 content::NotificationRegistrar notification_registrar_; | 349 content::NotificationRegistrar notification_registrar_; |
| 306 | 350 |
| 307 // A counter to generate a unique request id for a context menu request. | 351 // A counter to generate a unique request id for a context menu request. |
| 308 // We only need the ids to be unique for a given WebViewGuest. | 352 // We only need the ids to be unique for a given WebViewGuest. |
| 309 int pending_context_menu_request_id_; | 353 int pending_context_menu_request_id_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 scoped_ptr<RenderViewContextMenu> pending_menu_; | 389 scoped_ptr<RenderViewContextMenu> pending_menu_; |
| 346 | 390 |
| 347 #if defined(OS_CHROMEOS) | 391 #if defined(OS_CHROMEOS) |
| 348 // Subscription to receive notifications on changes to a11y settings. | 392 // Subscription to receive notifications on changes to a11y settings. |
| 349 scoped_ptr<chromeos::AccessibilityStatusSubscription> | 393 scoped_ptr<chromeos::AccessibilityStatusSubscription> |
| 350 accessibility_subscription_; | 394 accessibility_subscription_; |
| 351 #endif | 395 #endif |
| 352 | 396 |
| 353 std::map<int, int> bridge_id_to_request_id_map_; | 397 std::map<int, int> bridge_id_to_request_id_map_; |
| 354 | 398 |
| 399 // Tracks the name, and target URL of the new window and whether or not it has | |
| 400 // changed since the WebContents has been created and before the new window | |
| 401 // has been attached to a BrowserPlugin. Once the first navigation commits, we | |
| 402 // no longer track this information. | |
| 403 struct NewWindowInfo { | |
| 404 GURL url; | |
| 405 std::string name; | |
| 406 NewWindowInfo(const GURL& url, const std::string& name) : | |
| 407 url(url), | |
| 408 name(name) {} | |
| 409 }; | |
| 410 | |
| 411 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | |
| 412 PendingWindowMap pending_new_windows_; | |
| 413 | |
| 355 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 414 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
| 356 }; | 415 }; |
| 357 | 416 |
| 358 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 417 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
| OLD | NEW |