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

Side by Side Diff: chrome/browser/guest_view/guest_view_base.h

Issue 257823005: [Sheriff] Revert "Revert "Revert 266297 "1. Handle the case of empty embedder_extension_id...""" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/guest_view/guest_view.h ('k') | chrome/browser/guest_view/guest_view_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
7
8 #include <queue>
9
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
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 GuestViewBase is the base class browser-side API implementation for a
20 // <*view> tag. GuestViewBase maintains an association between a guest
21 // WebContents and an embedder WebContents. It receives events issued from
22 // the guest and relays them to the embedder.
23 class GuestViewBase : public content::BrowserPluginGuestDelegate {
24 public:
25 class Event {
26 public:
27 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args);
28 ~Event();
29
30 const std::string& name() const { return name_; }
31
32 scoped_ptr<base::DictionaryValue> GetArguments();
33
34 private:
35 const std::string name_;
36 scoped_ptr<base::DictionaryValue> args_;
37 };
38
39 // Returns a *ViewGuest if this GuestView is of the given view type.
40 template <typename T>
41 T* As() {
42 if (GetViewType() == T::Type) {
43 return static_cast<T*>(this);
44 }
45 return NULL;
46 }
47
48 static GuestViewBase* Create(content::WebContents* guest_web_contents,
49 const std::string& embedder_extension_id,
50 const std::string& view_type);
51
52 static GuestViewBase* FromWebContents(content::WebContents* web_contents);
53
54 static GuestViewBase* From(int embedder_process_id, int instance_id);
55
56 // For GuestViewBases, we create special guest processes, which host the
57 // tag content separately from the main application that embeds the tag.
58 // A GuestViewBase can specify both the partition name and whether the storage
59 // for that partition should be persisted. Each tag gets a SiteInstance with
60 // a specially formatted URL, based on the application it is hosted by and
61 // the partition requested by it. The format for that URL is:
62 // chrome-guest://partition_domain/persist?partition_name
63 static bool GetGuestPartitionConfigForSite(const GURL& site,
64 std::string* partition_domain,
65 std::string* partition_name,
66 bool* in_memory);
67
68 // By default, JavaScript and images are enabled in guest content.
69 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules,
70 bool incognito);
71
72 virtual const std::string& GetViewType() const = 0;
73
74 virtual void Attach(content::WebContents* embedder_web_contents,
75 const base::DictionaryValue& args);
76
77 content::WebContents* embedder_web_contents() const {
78 return embedder_web_contents_;
79 }
80
81 // Returns the guest WebContents.
82 content::WebContents* guest_web_contents() const {
83 return guest_web_contents_;
84 }
85
86 // Returns whether this guest has an associated embedder.
87 bool attached() const { return !!embedder_web_contents_; }
88
89 // Returns the instance ID of the <*view> element.
90 int view_instance_id() const { return view_instance_id_; }
91
92 // Returns the instance ID of the guest WebContents.
93 int guest_instance_id() const { return guest_instance_id_; }
94
95 // Returns the extension ID of the embedder.
96 const std::string& embedder_extension_id() const {
97 return embedder_extension_id_;
98 }
99
100 // Returns whether this GuestView is embedded in an extension/app.
101 bool in_extension() const { return !embedder_extension_id_.empty(); }
102
103 // Returns the user browser context of the embedder.
104 content::BrowserContext* browser_context() const { return browser_context_; }
105
106 // Returns the embedder's process ID.
107 int embedder_render_process_id() const { return embedder_render_process_id_; }
108
109 protected:
110 GuestViewBase(content::WebContents* guest_web_contents,
111 const std::string& embedder_extension_id);
112 virtual ~GuestViewBase();
113
114 // Dispatches an event |event_name| to the embedder with the |event| fields.
115 void DispatchEvent(Event* event);
116
117 private:
118 void SendQueuedEvents();
119
120 content::WebContents* const guest_web_contents_;
121 content::WebContents* embedder_web_contents_;
122 const std::string embedder_extension_id_;
123 int embedder_render_process_id_;
124 content::BrowserContext* const browser_context_;
125 // |guest_instance_id_| is a profile-wide unique identifier for a guest
126 // WebContents.
127 const int guest_instance_id_;
128 // |view_instance_id_| is an identifier that's unique within a particular
129 // embedder RenderViewHost for a particular <*view> instance.
130 int view_instance_id_;
131
132 // This is a queue of Events that are destined to be sent to the embedder once
133 // the guest is attached to a particular embedder.
134 std::deque<linked_ptr<Event> > pending_events_;
135
136 // This is used to ensure pending tasks will not fire after this object is
137 // destroyed.
138 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_;
139
140 DISALLOW_COPY_AND_ASSIGN(GuestViewBase);
141 };
142
143 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/guest_view.h ('k') | chrome/browser/guest_view/guest_view_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698