| 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/guest_view/web_view/javascript_dialog_helper.h" | 11 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" |
| 12 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" | 12 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" |
| 13 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | 13 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
| 14 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 14 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 15 #include "chrome/common/extensions/api/web_view_internal.h" | |
| 16 #include "content/public/browser/javascript_dialog_manager.h" | 15 #include "content/public/browser/javascript_dialog_manager.h" |
| 17 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 19 #include "extensions/browser/guest_view/guest_view.h" | 18 #include "extensions/browser/guest_view/guest_view.h" |
| 19 #include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h" |
| 20 #include "extensions/browser/script_executor.h" | 20 #include "extensions/browser/script_executor.h" |
| 21 #include "third_party/WebKit/public/web/WebFindOptions.h" | 21 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 22 | 22 |
| 23 #if defined(OS_CHROMEOS) | |
| 24 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 25 #endif | |
| 26 | |
| 27 class RenderViewContextMenu; | |
| 28 | |
| 29 namespace ui { | |
| 30 class SimpleMenuModel; | |
| 31 } // namespace ui | |
| 32 | |
| 33 namespace extensions { | 23 namespace extensions { |
| 34 | 24 |
| 35 namespace webview_api = api::web_view_internal; | |
| 36 | |
| 37 class WebViewInternalFindFunction; | 25 class WebViewInternalFindFunction; |
| 38 | 26 |
| 39 // A WebViewGuest provides the browser-side implementation of the <webview> API | 27 // A WebViewGuest provides the browser-side implementation of the <webview> API |
| 40 // and manages the dispatch of <webview> extension events. WebViewGuest is | 28 // and manages the dispatch of <webview> extension events. WebViewGuest is |
| 41 // created on attachment. That is, when a guest WebContents is associated with | 29 // created on attachment. That is, when a guest WebContents is associated with |
| 42 // a particular embedder WebContents. This happens on either initial navigation | 30 // 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 | 31 // or through the use of the New Window API, when a new window is attached to |
| 44 // a particular <webview>. | 32 // a particular <webview>. |
| 45 class WebViewGuest : public GuestView<WebViewGuest>, | 33 class WebViewGuest : public GuestView<WebViewGuest>, |
| 46 public content::NotificationObserver { | 34 public content::NotificationObserver { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 | 50 |
| 63 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a | 51 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a |
| 64 // WebViewGuest. | 52 // WebViewGuest. |
| 65 static int GetViewInstanceId(content::WebContents* contents); | 53 static int GetViewInstanceId(content::WebContents* contents); |
| 66 | 54 |
| 67 static const char Type[]; | 55 static const char Type[]; |
| 68 | 56 |
| 69 // Request navigating the guest to the provided |src| URL. | 57 // Request navigating the guest to the provided |src| URL. |
| 70 void NavigateGuest(const std::string& src); | 58 void NavigateGuest(const std::string& src); |
| 71 | 59 |
| 72 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; | |
| 73 // Shows the context menu for the guest. | 60 // Shows the context menu for the guest. |
| 74 // |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 |
| 75 // menu items to contain only the items from |items|. | 62 // menu items to contain only the items from |items|. |
| 76 // |items| == NULL means no filtering will be applied. | 63 // |items| == NULL means no filtering will be applied. |
| 77 void ShowContextMenu(int request_id, const MenuItemVector* items); | 64 void ShowContextMenu( |
| 65 int request_id, |
| 66 const WebViewGuestDelegate::MenuItemVector* items); |
| 78 | 67 |
| 79 // Sets the frame name of the guest. | 68 // Sets the frame name of the guest. |
| 80 void SetName(const std::string& name); | 69 void SetName(const std::string& name); |
| 81 | 70 |
| 82 // Set the zoom factor. | 71 // Set the zoom factor. |
| 83 void SetZoom(double zoom_factor); | 72 void SetZoom(double zoom_factor); |
| 84 | 73 |
| 85 // GuestViewBase implementation. | 74 // GuestViewBase implementation. |
| 86 virtual const char* GetAPINamespace() OVERRIDE; | 75 virtual const char* GetAPINamespace() OVERRIDE; |
| 87 virtual void CreateWebContents( | 76 virtual void CreateWebContents( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 225 |
| 237 ScriptExecutor* script_executor() { return script_executor_.get(); } | 226 ScriptExecutor* script_executor() { return script_executor_.get(); } |
| 238 | 227 |
| 239 private: | 228 private: |
| 240 friend class WebViewPermissionHelper; | 229 friend class WebViewPermissionHelper; |
| 241 WebViewGuest(content::BrowserContext* browser_context, | 230 WebViewGuest(content::BrowserContext* browser_context, |
| 242 int guest_instance_id); | 231 int guest_instance_id); |
| 243 | 232 |
| 244 virtual ~WebViewGuest(); | 233 virtual ~WebViewGuest(); |
| 245 | 234 |
| 246 // Returns the top level items (ignoring submenus) as Value. | |
| 247 static scoped_ptr<base::ListValue> MenuModelToValue( | |
| 248 const ui::SimpleMenuModel& menu_model); | |
| 249 | |
| 250 void AttachWebViewHelpers(content::WebContents* contents); | 235 void AttachWebViewHelpers(content::WebContents* contents); |
| 251 | 236 |
| 252 void OnWebViewNewWindowResponse(int new_window_instance_id, | 237 void OnWebViewNewWindowResponse(int new_window_instance_id, |
| 253 bool allow, | 238 bool allow, |
| 254 const std::string& user_input); | 239 const std::string& user_input); |
| 255 | 240 |
| 256 // WebContentsObserver implementation. | 241 // WebContentsObserver implementation. |
| 257 virtual void DidCommitProvisionalLoadForFrame( | 242 virtual void DidCommitProvisionalLoadForFrame( |
| 258 content::RenderFrameHost* render_frame_host, | 243 content::RenderFrameHost* render_frame_host, |
| 259 const GURL& url, | 244 const GURL& url, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 284 | 269 |
| 285 // Called when a redirect notification occurs. | 270 // Called when a redirect notification occurs. |
| 286 void LoadRedirect(const GURL& old_url, | 271 void LoadRedirect(const GURL& old_url, |
| 287 const GURL& new_url, | 272 const GURL& new_url, |
| 288 bool is_top_level); | 273 bool is_top_level); |
| 289 | 274 |
| 290 void PushWebViewStateToIOThread(); | 275 void PushWebViewStateToIOThread(); |
| 291 static void RemoveWebViewStateFromIOThread( | 276 static void RemoveWebViewStateFromIOThread( |
| 292 content::WebContents* web_contents); | 277 content::WebContents* web_contents); |
| 293 | 278 |
| 294 #if defined(OS_CHROMEOS) | |
| 295 // Notification of a change in the state of an accessibility setting. | |
| 296 void OnAccessibilityStatusChanged( | |
| 297 const chromeos::AccessibilityStatusEventDetails& details); | |
| 298 #endif | |
| 299 | |
| 300 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | |
| 301 | |
| 302 void LoadURLWithParams(const GURL& url, | 279 void LoadURLWithParams(const GURL& url, |
| 303 const content::Referrer& referrer, | 280 const content::Referrer& referrer, |
| 304 content::PageTransition transition_type, | 281 content::PageTransition transition_type, |
| 305 content::WebContents* web_contents); | 282 content::WebContents* web_contents); |
| 306 | 283 |
| 307 void RequestNewWindowPermission( | 284 void RequestNewWindowPermission( |
| 308 WindowOpenDisposition disposition, | 285 WindowOpenDisposition disposition, |
| 309 const gfx::Rect& initial_bounds, | 286 const gfx::Rect& initial_bounds, |
| 310 bool user_gesture, | 287 bool user_gesture, |
| 311 content::WebContents* new_contents); | 288 content::WebContents* new_contents); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 333 | 310 |
| 334 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); | 311 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); |
| 335 | 312 |
| 336 void SetUpAutoSize(); | 313 void SetUpAutoSize(); |
| 337 | 314 |
| 338 ObserverList<ScriptExecutionObserver> script_observers_; | 315 ObserverList<ScriptExecutionObserver> script_observers_; |
| 339 scoped_ptr<ScriptExecutor> script_executor_; | 316 scoped_ptr<ScriptExecutor> script_executor_; |
| 340 | 317 |
| 341 content::NotificationRegistrar notification_registrar_; | 318 content::NotificationRegistrar notification_registrar_; |
| 342 | 319 |
| 343 // A counter to generate a unique request id for a context menu request. | |
| 344 // We only need the ids to be unique for a given WebViewGuest. | |
| 345 int pending_context_menu_request_id_; | |
| 346 | |
| 347 // True if the user agent is overridden. | 320 // True if the user agent is overridden. |
| 348 bool is_overriding_user_agent_; | 321 bool is_overriding_user_agent_; |
| 349 | 322 |
| 350 // Set to |true| if ChromeVox was already injected in main frame. | |
| 351 bool chromevox_injected_; | |
| 352 | |
| 353 // Stores the current zoom factor. | |
| 354 double current_zoom_factor_; | |
| 355 | |
| 356 // Stores the window name of the main frame of the guest. | 323 // Stores the window name of the main frame of the guest. |
| 357 std::string name_; | 324 std::string name_; |
| 358 | 325 |
| 359 // Handles find requests and replies for the webview find API. | 326 // Handles find requests and replies for the webview find API. |
| 360 WebViewFindHelper find_helper_; | 327 WebViewFindHelper find_helper_; |
| 361 | 328 |
| 362 // Handles the JavaScript dialog requests. | 329 // Handles the JavaScript dialog requests. |
| 363 JavaScriptDialogHelper javascript_dialog_helper_; | 330 JavaScriptDialogHelper javascript_dialog_helper_; |
| 364 | 331 |
| 365 // Handels permission requests. | 332 // Handels permission requests. |
| 366 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; | 333 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; |
| 367 | 334 |
| 335 scoped_ptr<WebViewGuestDelegate> web_view_guest_delegate_; |
| 336 |
| 368 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, | 337 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, |
| 369 bool final_update); | 338 bool final_update); |
| 370 | 339 |
| 371 // Holds the RenderViewContextMenu that has been built but yet to be | |
| 372 // shown. This is .Reset() after ShowContextMenu(). | |
| 373 scoped_ptr<RenderViewContextMenu> pending_menu_; | |
| 374 | |
| 375 #if defined(OS_CHROMEOS) | |
| 376 // Subscription to receive notifications on changes to a11y settings. | |
| 377 scoped_ptr<chromeos::AccessibilityStatusSubscription> | |
| 378 accessibility_subscription_; | |
| 379 #endif | |
| 380 | |
| 381 // Tracks the name, and target URL of the new window. Once the first | 340 // Tracks the name, and target URL of the new window. Once the first |
| 382 // navigation commits, we no longer track this information. | 341 // navigation commits, we no longer track this information. |
| 383 struct NewWindowInfo { | 342 struct NewWindowInfo { |
| 384 GURL url; | 343 GURL url; |
| 385 std::string name; | 344 std::string name; |
| 386 bool changed; | 345 bool changed; |
| 387 NewWindowInfo(const GURL& url, const std::string& name) : | 346 NewWindowInfo(const GURL& url, const std::string& name) : |
| 388 url(url), | 347 url(url), |
| 389 name(name), | 348 name(name), |
| 390 changed(false) {} | 349 changed(false) {} |
| 391 }; | 350 }; |
| 392 | 351 |
| 393 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 352 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
| 394 PendingWindowMap pending_new_windows_; | 353 PendingWindowMap pending_new_windows_; |
| 395 | 354 |
| 396 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 355 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
| 397 }; | 356 }; |
| 398 | 357 |
| 399 } // namespace extensions | 358 } // namespace extensions |
| 400 | 359 |
| 401 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 360 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
| OLD | NEW |