blob: 8b6e03b73087c1e70c33604873a43d7dc42b7ba1 [file] [log] [blame]
[email protected]0533cc6d2013-06-27 22:44:051// Copyright 2013 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_GUESTVIEW_GUESTVIEW_H_
6#define CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_
7
[email protected]738f57a2013-06-29 21:06:548#include <queue>
9
[email protected]0533cc6d2013-06-27 22:44:0510#include "base/values.h"
[email protected]4c0e8272013-07-03 23:39:2211#include "content/public/browser/browser_plugin_guest_delegate.h"
[email protected]0533cc6d2013-06-27 22:44:0512#include "content/public/browser/web_contents.h"
13
14class AdViewGuest;
15class WebViewGuest;
[email protected]06153f02013-12-04 03:01:2816struct RendererContentSettingRules;
[email protected]0533cc6d2013-06-27 22:44:0517
18// A GuestView is the base class browser-side API implementation for a <*view>
19// tag. GuestView maintains an association between a guest WebContents and an
20// embedder WebContents. It receives events issued from the guest and relays
21// them to the embedder.
[email protected]4c0e8272013-07-03 23:39:2222class GuestView : public content::BrowserPluginGuestDelegate {
[email protected]0533cc6d2013-06-27 22:44:0523 public:
[email protected]738f57a2013-06-29 21:06:5424 enum Type {
25 WEBVIEW,
26 ADVIEW,
27 UNKNOWN
28 };
29
30 class Event {
31 public:
[email protected]0aad6472013-12-04 18:25:3832 Event(const std::string& name, scoped_ptr<DictionaryValue> args);
[email protected]738f57a2013-06-29 21:06:5433 ~Event();
34
[email protected]0aad6472013-12-04 18:25:3835 const std::string& name() const { return name_; }
[email protected]738f57a2013-06-29 21:06:5436
37 scoped_ptr<DictionaryValue> GetArguments();
38
39 private:
[email protected]0aad6472013-12-04 18:25:3840 const std::string name_;
[email protected]738f57a2013-06-29 21:06:5441 scoped_ptr<DictionaryValue> args_;
42 };
43
[email protected]50c827d2013-09-13 21:36:0944 static Type GetViewTypeFromString(const std::string& api_type);
45
46 static GuestView* Create(content::WebContents* guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:1947 const std::string& extension_id,
[email protected]50c827d2013-09-13 21:36:0948 Type view_type);
[email protected]738f57a2013-06-29 21:06:5449
50 static GuestView* FromWebContents(content::WebContents* web_contents);
[email protected]0533cc6d2013-06-27 22:44:0551
52 static GuestView* From(int embedder_process_id, int instance_id);
53
[email protected]3f24f97c2013-11-17 21:53:3354 // For GuestViews, we create special guest processes, which host the
55 // tag content separately from the main application that embeds the tag.
56 // A GuestView can specify both the partition name and whether the storage
57 // for that partition should be persisted. Each tag gets a SiteInstance with
58 // a specially formatted URL, based on the application it is hosted by and
59 // the partition requested by it. The format for that URL is:
60 // chrome-guest://partition_domain/persist?partition_name
61 static bool GetGuestPartitionConfigForSite(const GURL& site,
62 std::string* partition_domain,
63 std::string* partition_name,
64 bool* in_memory);
65
[email protected]06153f02013-12-04 03:01:2866 // By default, JavaScript and images are enabled in guest content.
67 static void GetDefaultContentSettingRules(
68 RendererContentSettingRules* rules, bool incognito);
69
[email protected]738f57a2013-06-29 21:06:5470 virtual void Attach(content::WebContents* embedder_web_contents,
[email protected]738f57a2013-06-29 21:06:5471 const base::DictionaryValue& args);
72
[email protected]0533cc6d2013-06-27 22:44:0573 content::WebContents* embedder_web_contents() const {
74 return embedder_web_contents_;
75 }
76
77 // Returns the guest WebContents.
[email protected]738f57a2013-06-29 21:06:5478 content::WebContents* guest_web_contents() const {
79 return guest_web_contents_;
80 }
81
82 virtual Type GetViewType() const;
[email protected]0533cc6d2013-06-27 22:44:0583
84 // Returns a WebViewGuest if this GuestView belongs to a <webview>.
85 virtual WebViewGuest* AsWebView() = 0;
86
87 // Returns an AdViewGuest if the GuestView belongs to an <adview>.
88 virtual AdViewGuest* AsAdView() = 0;
89
[email protected]738f57a2013-06-29 21:06:5490 // Returns whether this guest has an associated embedder.
91 bool attached() const { return !!embedder_web_contents_; }
92
[email protected]0533cc6d2013-06-27 22:44:0593 // Returns the instance ID of the <*view> element.
94 int view_instance_id() const { return view_instance_id_; }
95
96 // Returns the instance ID of the guest WebContents.
97 int guest_instance_id() const { return guest_instance_id_; }
98
99 // Returns the extension ID of the embedder.
100 const std::string& extension_id() const { return extension_id_; }
101
102 // Returns the user browser context of the embedder.
103 content::BrowserContext* browser_context() const { return browser_context_; }
104
105 // Returns the embedder's process ID.
106 int embedder_render_process_id() const { return embedder_render_process_id_; }
107
108 protected:
[email protected]dbbce92c2013-10-31 16:51:19109 GuestView(content::WebContents* guest_web_contents,
110 const std::string& extension_id);
[email protected]0533cc6d2013-06-27 22:44:05111 virtual ~GuestView();
112
113 // Dispatches an event |event_name| to the embedder with the |event| fields.
[email protected]738f57a2013-06-29 21:06:54114 void DispatchEvent(Event* event);
[email protected]0533cc6d2013-06-27 22:44:05115
116 private:
[email protected]738f57a2013-06-29 21:06:54117 void SendQueuedEvents();
118
[email protected]70e7c0e2013-11-08 00:33:21119 content::WebContents* const guest_web_contents_;
[email protected]0533cc6d2013-06-27 22:44:05120 content::WebContents* embedder_web_contents_;
[email protected]dbbce92c2013-10-31 16:51:19121 const std::string extension_id_;
[email protected]738f57a2013-06-29 21:06:54122 int embedder_render_process_id_;
[email protected]70e7c0e2013-11-08 00:33:21123 content::BrowserContext* const browser_context_;
[email protected]0533cc6d2013-06-27 22:44:05124 // |guest_instance_id_| is a profile-wide unique identifier for a guest
125 // WebContents.
126 const int guest_instance_id_;
127 // |view_instance_id_| is an identifier that's unique within a particular
128 // embedder RenderViewHost for a particular <*view> instance.
[email protected]738f57a2013-06-29 21:06:54129 int view_instance_id_;
130
131 // This is a queue of Events that are destined to be sent to the embedder once
132 // the guest is attached to a particular embedder.
133 std::queue<Event*> pending_events_;
[email protected]0533cc6d2013-06-27 22:44:05134
135 DISALLOW_COPY_AND_ASSIGN(GuestView);
136};
137
138#endif // CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_