| 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" | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|   37  |   37  | 
|   38 // A WebViewGuest provides the browser-side implementation of the <webview> API |   38 // A WebViewGuest provides the browser-side implementation of the <webview> API | 
|   39 // and manages the dispatch of <webview> extension events. WebViewGuest is |   39 // and manages the dispatch of <webview> extension events. WebViewGuest is | 
|   40 // created on attachment. That is, when a guest WebContents is associated with |   40 // created on attachment. That is, when a guest WebContents is associated with | 
|   41 // a particular embedder WebContents. This happens on either initial navigation |   41 // a particular embedder WebContents. This happens on either initial navigation | 
|   42 // or through the use of the New Window API, when a new window is attached to |   42 // or through the use of the New Window API, when a new window is attached to | 
|   43 // a particular <webview>. |   43 // a particular <webview>. | 
|   44 class WebViewGuest : public GuestView<WebViewGuest>, |   44 class WebViewGuest : public GuestView<WebViewGuest>, | 
|   45                      public content::NotificationObserver { |   45                      public content::NotificationObserver { | 
|   46  public: |   46  public: | 
|   47   WebViewGuest(int guest_instance_id, |   47   explicit WebViewGuest(int guest_instance_id); | 
|   48                content::WebContents* guest_web_contents, |  | 
|   49                const std::string& embedder_extension_id); |  | 
|   50  |   48  | 
|   51   // For WebViewGuest, we create special guest processes, which host the |   49   // For WebViewGuest, we create special guest processes, which host the | 
|   52   // tag content separately from the main application that embeds the tag. |   50   // tag content separately from the main application that embeds the tag. | 
|   53   // A <webview> can specify both the partition name and whether the storage |   51   // A <webview> can specify both the partition name and whether the storage | 
|   54   // for that partition should be persisted. Each tag gets a SiteInstance with |   52   // for that partition should be persisted. Each tag gets a SiteInstance with | 
|   55   // a specially formatted URL, based on the application it is hosted by and |   53   // a specially formatted URL, based on the application it is hosted by and | 
|   56   // the partition requested by it. The format for that URL is: |   54   // the partition requested by it. The format for that URL is: | 
|   57   // chrome-guest://partition_domain/persist?partition_name |   55   // chrome-guest://partition_domain/persist?partition_name | 
|   58   static bool GetGuestPartitionConfigForSite(const GURL& site, |   56   static bool GetGuestPartitionConfigForSite(const GURL& site, | 
|   59                                              std::string* partition_domain, |   57                                              std::string* partition_domain, | 
|   60                                              std::string* partition_name, |   58                                              std::string* partition_name, | 
|   61                                              bool* in_memory); |   59                                              bool* in_memory); | 
|   62  |   60  | 
|   63   // Returns guestview::kInstanceIDNone if |contents| does not correspond to a |   61   // Returns guestview::kInstanceIDNone if |contents| does not correspond to a | 
|   64   // WebViewGuest. |   62   // WebViewGuest. | 
|   65   static int GetViewInstanceId(content::WebContents* contents); |   63   static int GetViewInstanceId(content::WebContents* contents); | 
|   66   // Parses partition related parameters from |extra_params|. |   64  | 
|   67   // |storage_partition_id| is the parsed partition ID and |persist_storage| |  | 
|   68   // specifies whether or not the partition is in memory. |  | 
|   69   static void ParsePartitionParam(const base::DictionaryValue* extra_params, |  | 
|   70                                   std::string* storage_partition_id, |  | 
|   71                                   bool* persist_storage); |  | 
|   72   static const char Type[]; |   65   static const char Type[]; | 
|   73  |   66  | 
|   74   // Request navigating the guest to the provided |src| URL. |   67   // Request navigating the guest to the provided |src| URL. | 
|   75   void NavigateGuest(const std::string& src); |   68   void NavigateGuest(const std::string& src); | 
|   76  |   69  | 
|   77   typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; |   70   typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; | 
|   78   // Shows the context menu for the guest. |   71   // Shows the context menu for the guest. | 
|   79   // |items| acts as a filter. This restricts the current context's default |   72   // |items| acts as a filter. This restricts the current context's default | 
|   80   // menu items to contain only the items from |items|. |   73   // menu items to contain only the items from |items|. | 
|   81   // |items| == NULL means no filtering will be applied. |   74   // |items| == NULL means no filtering will be applied. | 
|   82   void ShowContextMenu(int request_id, const MenuItemVector* items); |   75   void ShowContextMenu(int request_id, const MenuItemVector* items); | 
|   83  |   76  | 
|   84   // Sets the frame name of the guest. |   77   // Sets the frame name of the guest. | 
|   85   void SetName(const std::string& name); |   78   void SetName(const std::string& name); | 
|   86  |   79  | 
|   87   // Set the zoom factor. |   80   // Set the zoom factor. | 
|   88   void SetZoom(double zoom_factor); |   81   void SetZoom(double zoom_factor); | 
|   89  |   82  | 
|   90   // GuestViewBase implementation. |   83   // GuestViewBase implementation. | 
 |   84   virtual void CreateWebContents( | 
 |   85       const std::string& embedder_extension_id, | 
 |   86       int embedder_render_process_id, | 
 |   87       const base::DictionaryValue& create_params, | 
 |   88       const WebContentsCreatedCallback& callback) OVERRIDE; | 
|   91   virtual void DidAttachToEmbedder() OVERRIDE; |   89   virtual void DidAttachToEmbedder() OVERRIDE; | 
 |   90   virtual void DidInitialize() OVERRIDE; | 
|   92   virtual void DidStopLoading() OVERRIDE; |   91   virtual void DidStopLoading() OVERRIDE; | 
|   93   virtual void EmbedderDestroyed() OVERRIDE; |   92   virtual void EmbedderDestroyed() OVERRIDE; | 
|   94   virtual void GuestDestroyed() OVERRIDE; |   93   virtual void GuestDestroyed() OVERRIDE; | 
|   95   virtual bool IsDragAndDropEnabled() const OVERRIDE; |   94   virtual bool IsDragAndDropEnabled() const OVERRIDE; | 
|   96   virtual void WillAttachToEmbedder() OVERRIDE; |   95   virtual void WillAttachToEmbedder() OVERRIDE; | 
|   97   virtual void WillDestroy() OVERRIDE; |   96   virtual void WillDestroy() OVERRIDE; | 
|   98  |   97  | 
|   99   // WebContentsDelegate implementation. |   98   // WebContentsDelegate implementation. | 
|  100   virtual bool AddMessageToConsole(content::WebContents* source, |   99   virtual bool AddMessageToConsole(content::WebContents* source, | 
|  101                                    int32 level, |  100                                    int32 level, | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  144   virtual content::WebContents* OpenURLFromTab( |  143   virtual content::WebContents* OpenURLFromTab( | 
|  145       content::WebContents* source, |  144       content::WebContents* source, | 
|  146       const content::OpenURLParams& params) OVERRIDE; |  145       const content::OpenURLParams& params) OVERRIDE; | 
|  147   virtual void WebContentsCreated(content::WebContents* source_contents, |  146   virtual void WebContentsCreated(content::WebContents* source_contents, | 
|  148                                   int opener_render_frame_id, |  147                                   int opener_render_frame_id, | 
|  149                                   const base::string16& frame_name, |  148                                   const base::string16& frame_name, | 
|  150                                   const GURL& target_url, |  149                                   const GURL& target_url, | 
|  151                                   content::WebContents* new_contents) OVERRIDE; |  150                                   content::WebContents* new_contents) OVERRIDE; | 
|  152  |  151  | 
|  153   // BrowserPluginGuestDelegate implementation. |  152   // BrowserPluginGuestDelegate implementation. | 
 |  153   virtual content::WebContents* CreateNewGuestWindow( | 
 |  154       const content::WebContents::CreateParams& create_params) OVERRIDE; | 
|  154   virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) |  155   virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) | 
|  155       OVERRIDE; |  156       OVERRIDE; | 
|  156   virtual void RequestPointerLockPermission( |  157   virtual void RequestPointerLockPermission( | 
|  157       bool user_gesture, |  158       bool user_gesture, | 
|  158       bool last_unlocked_by_target, |  159       bool last_unlocked_by_target, | 
|  159       const base::Callback<void(bool)>& callback) OVERRIDE; |  160       const base::Callback<void(bool)>& callback) OVERRIDE; | 
|  160   // NotificationObserver implementation. |  161   // NotificationObserver implementation. | 
|  161   virtual void Observe(int type, |  162   virtual void Observe(int type, | 
|  162                        const content::NotificationSource& source, |  163                        const content::NotificationSource& source, | 
|  163                        const content::NotificationDetails& details) OVERRIDE; |  164                        const content::NotificationDetails& details) OVERRIDE; | 
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  422  |  423  | 
|  423   // Notification that a load in the guest resulted in abort. Note that |url| |  424   // Notification that a load in the guest resulted in abort. Note that |url| | 
|  424   // may be invalid. |  425   // may be invalid. | 
|  425   void LoadAbort(bool is_top_level, |  426   void LoadAbort(bool is_top_level, | 
|  426                  const GURL& url, |  427                  const GURL& url, | 
|  427                  const std::string& error_type); |  428                  const std::string& error_type); | 
|  428  |  429  | 
|  429   void OnUpdateFrameName(bool is_top_level, const std::string& name); |  430   void OnUpdateFrameName(bool is_top_level, const std::string& name); | 
|  430  |  431  | 
|  431   // Creates a new guest window owned by this WebViewGuest. |  432   // Creates a new guest window owned by this WebViewGuest. | 
|  432   WebViewGuest* CreateNewGuestWindow(const content::OpenURLParams& params); |  433   WebViewGuest* CreateNewGuestWebViewWindow( | 
 |  434       const content::OpenURLParams& params); | 
|  433  |  435  | 
|  434   bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); |  436   bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); | 
|  435  |  437  | 
|  436   ObserverList<extensions::TabHelper::ScriptExecutionObserver> |  438   ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 
|  437       script_observers_; |  439       script_observers_; | 
|  438   scoped_ptr<extensions::ScriptExecutor> script_executor_; |  440   scoped_ptr<extensions::ScriptExecutor> script_executor_; | 
|  439  |  441  | 
|  440   content::NotificationRegistrar notification_registrar_; |  442   content::NotificationRegistrar notification_registrar_; | 
|  441  |  443  | 
|  442   // A counter to generate a unique request id for a context menu request. |  444   // A counter to generate a unique request id for a context menu request. | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  498         changed(false) {} |  500         changed(false) {} | 
|  499   }; |  501   }; | 
|  500  |  502  | 
|  501   typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |  503   typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 
|  502   PendingWindowMap pending_new_windows_; |  504   PendingWindowMap pending_new_windows_; | 
|  503  |  505  | 
|  504   DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |  506   DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 
|  505 }; |  507 }; | 
|  506  |  508  | 
|  507 #endif  // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |  509 #endif  // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 
| OLD | NEW |