Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/guestview/guestview.h

Issue 237533008: Refactor GuestView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes are made. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/guestview/adview/adview_guest.cc ('k') | chrome/browser/guestview/guestview.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_GUESTVIEW_GUESTVIEW_H_ 5 #ifndef CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_
6 #define CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ 6 #define CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_
7 7
8 #include <queue> 8 #include "chrome/browser/guestview/guestview_base.h"
9 9
10 #include "base/memory/weak_ptr.h" 10 template <typename T>
11 #include "base/values.h" 11 class GuestView : public GuestViewBase {
sky 2014/04/24 16:31:24 Noticed this in looking at gyp changes. This file
Xi Han 2014/04/24 18:14:50 Done.
12 #include "content/public/browser/browser_plugin_guest_delegate.h"
13 #include "content/public/browser/web_contents.h"
14
15 class AdViewGuest;
16 class WebViewGuest;
17 struct RendererContentSettingRules;
18
19 // A GuestView is the base class browser-side API implementation for a <*view>
20 // tag. GuestView maintains an association between a guest WebContents and an
21 // embedder WebContents. It receives events issued from the guest and relays
22 // them to the embedder.
23 class GuestView : public content::BrowserPluginGuestDelegate {
24 public: 12 public:
25 enum Type { 13 static T* From(int embedder_process_id, int guest_instance_id) {
26 WEBVIEW, 14 GuestViewBase* guest =
27 ADVIEW, 15 GuestViewBase::From(embedder_process_id, guest_instance_id);
28 UNKNOWN 16 if (!guest)
29 }; 17 return NULL;
30 18 return guest->As<T>();
31 class Event {
32 public:
33 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args);
34 ~Event();
35
36 const std::string& name() const { return name_; }
37
38 scoped_ptr<base::DictionaryValue> GetArguments();
39
40 private:
41 const std::string name_;
42 scoped_ptr<base::DictionaryValue> args_;
43 };
44
45 static Type GetViewTypeFromString(const std::string& api_type);
46
47 static GuestView* Create(content::WebContents* guest_web_contents,
48 const std::string& embedder_extension_id,
49 Type view_type);
50
51 static GuestView* FromWebContents(content::WebContents* web_contents);
52
53 static GuestView* From(int embedder_process_id, int instance_id);
54
55 // For GuestViews, we create special guest processes, which host the
56 // tag content separately from the main application that embeds the tag.
57 // A GuestView can specify both the partition name and whether the storage
58 // for that partition should be persisted. Each tag gets a SiteInstance with
59 // a specially formatted URL, based on the application it is hosted by and
60 // the partition requested by it. The format for that URL is:
61 // chrome-guest://partition_domain/persist?partition_name
62 static bool GetGuestPartitionConfigForSite(const GURL& site,
63 std::string* partition_domain,
64 std::string* partition_name,
65 bool* in_memory);
66
67 // By default, JavaScript and images are enabled in guest content.
68 static void GetDefaultContentSettingRules(
69 RendererContentSettingRules* rules, bool incognito);
70
71 virtual void Attach(content::WebContents* embedder_web_contents,
72 const base::DictionaryValue& args);
73
74 content::WebContents* embedder_web_contents() const {
75 return embedder_web_contents_;
76 } 19 }
77 20
78 // Returns the guest WebContents. 21 static T* FromWebContents(content::WebContents* contents) {
79 content::WebContents* guest_web_contents() const { 22 GuestViewBase* guest = GuestViewBase::FromWebContents(contents);
80 return guest_web_contents_; 23 return guest ? guest->As<T>() : NULL;
81 } 24 }
82 25
83 virtual Type GetViewType() const; 26 // GuestViewBase implementation.
84 27 virtual const std::string& GetViewType() const OVERRIDE { return T::Type; }
85 // Returns a WebViewGuest if this GuestView belongs to a <webview>.
86 virtual WebViewGuest* AsWebView() = 0;
87
88 // Returns an AdViewGuest if the GuestView belongs to an <adview>.
89 virtual AdViewGuest* AsAdView() = 0;
90
91 // Returns whether this guest has an associated embedder.
92 bool attached() const { return !!embedder_web_contents_; }
93
94 // Returns the instance ID of the <*view> element.
95 int view_instance_id() const { return view_instance_id_; }
96
97 // Returns the instance ID of the guest WebContents.
98 int guest_instance_id() const { return guest_instance_id_; }
99
100 // Returns the extension ID of the embedder.
101 const std::string& embedder_extension_id() const {
102 return embedder_extension_id_;
103 }
104
105 // Returns whether this GuestView is embedded in an extension/app.
106 bool in_extension() const {
107 return !embedder_extension_id_.empty();
108 }
109
110 // Returns the user browser context of the embedder.
111 content::BrowserContext* browser_context() const { return browser_context_; }
112
113 // Returns the embedder's process ID.
114 int embedder_render_process_id() const { return embedder_render_process_id_; }
115 28
116 protected: 29 protected:
117 GuestView(content::WebContents* guest_web_contents, 30 GuestView(content::WebContents* guest_web_contents,
118 const std::string& embedder_extension_id); 31 const std::string& embedder_extension_id)
119 virtual ~GuestView(); 32 : GuestViewBase(guest_web_contents, embedder_extension_id) {}
120
121 // Dispatches an event |event_name| to the embedder with the |event| fields.
122 void DispatchEvent(Event* event);
123 33
124 private: 34 private:
125 void SendQueuedEvents();
126
127 content::WebContents* const guest_web_contents_;
128 content::WebContents* embedder_web_contents_;
129 const std::string embedder_extension_id_;
130 int embedder_render_process_id_;
131 content::BrowserContext* const browser_context_;
132 // |guest_instance_id_| is a profile-wide unique identifier for a guest
133 // WebContents.
134 const int guest_instance_id_;
135 // |view_instance_id_| is an identifier that's unique within a particular
136 // embedder RenderViewHost for a particular <*view> instance.
137 int view_instance_id_;
138
139 // This is a queue of Events that are destined to be sent to the embedder once
140 // the guest is attached to a particular embedder.
141 std::deque<linked_ptr<Event> > pending_events_;
142
143 // This is used to ensure pending tasks will not fire after this object is
144 // destroyed.
145 base::WeakPtrFactory<GuestView> weak_ptr_factory_;
146
147 DISALLOW_COPY_AND_ASSIGN(GuestView); 35 DISALLOW_COPY_AND_ASSIGN(GuestView);
148 }; 36 };
149 37
150 #endif // CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ 38 #endif // CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/guestview/adview/adview_guest.cc ('k') | chrome/browser/guestview/guestview.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698