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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_placeholder.cc

Issue 9609008: Implemented Browser Plugin (NOT FOR REVIEW) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated according to creis@'s comments Created 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "content/renderer/browser_plugin/browser_plugin_placeholder.h"
6
7 #include "base/atomic_sequence_num.h"
8 #include "base/id_map.h"
9 #include "base/lazy_instance.h"
10 #include "base/process.h"
11 #include "base/string_number_conversions.h"
12 #include "base/string_piece.h"
13 #include "base/string_util.h"
14 #include "base/values.h"
15 #include "content/common/view_messages.h"
16 #include "content/public/renderer/render_view.h"
17 #include "ipc/ipc_channel_handle.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
21 #include "webkit/plugins/webview_plugin.h"
22
23 static base::StaticAtomicSequenceNumber g_next_id;
24
25 // The global list of all Browser Plugin Placeholders within a process.
26 base::LazyInstance<IDMap<BrowserPluginPlaceholder> >::Leaky
27 g_all_placeholders = LAZY_INSTANCE_INITIALIZER;
28
29 using webkit::WebViewPlugin;
30 using WebKit::WebPlugin;
31 using WebKit::WebPluginContainer;
32
33 const char* const kPluginPlaceholderDataURL =
34 "about:blank";
35
36 // static
37 webkit::WebViewPlugin* BrowserPluginPlaceholder::Create(
38 content::RenderView* render_view,
39 WebKit::WebFrame* frame,
40 const WebKit::WebPluginParams& params) {
41 // TODO(fsamuel): Need a better loading screen at some point. Maybe this can
42 // be a part of the <browser> API?
43 // |browser_plugin| will destroy itself when its WebViewPlugin is going away.
44 BrowserPluginPlaceholder* browser_plugin = new BrowserPluginPlaceholder(
45 render_view, frame, params, "");
46 return browser_plugin->plugin();
47 }
48
49 // static
50 BrowserPluginPlaceholder* BrowserPluginPlaceholder::FromID(int id) {
51 return g_all_placeholders.Get().Lookup(id);
52 }
53
54 BrowserPluginPlaceholder::BrowserPluginPlaceholder(
55 content::RenderView* render_view,
56 WebKit::WebFrame* frame,
57 const WebKit::WebPluginParams& params,
58 const std::string& html_data)
59 : render_view_(render_view),
60 plugin_params_(params),
61 plugin_(webkit::WebViewPlugin::Create(
62 this, render_view->GetWebkitPreferences(), html_data,
63 GURL(kPluginPlaceholderDataURL))) {
64 id_ = g_next_id.GetNext();
65 RegisterPlaceholder(GetID(), this);
66
67 // By default we navigate to google.com
68 GetPluginParameters(0, 0, "http://www.google.com/");
69
70 // TODO(fsamuel): Request a browser plugin instance from the
71 // browser process.
72 }
73
74 BrowserPluginPlaceholder::~BrowserPluginPlaceholder() {
75 UnregisterPlaceholder(GetID());
76 }
77
78 void BrowserPluginPlaceholder::RegisterPlaceholder(
79 int id,
80 BrowserPluginPlaceholder* placeholder) {
81 g_all_placeholders.Get().AddWithID(placeholder, id);
82 }
83
84 void BrowserPluginPlaceholder::UnregisterPlaceholder(int id) {
85 if (g_all_placeholders.Get().Lookup(id))
86 g_all_placeholders.Get().Remove(id);
87 }
88
89 const WebKit::WebPluginParams& BrowserPluginPlaceholder::plugin_params() const {
90 return plugin_params_;
91 }
92
93 void BrowserPluginPlaceholder::GetPluginParameters(
94 int default_width, int default_height,
95 const std::string& default_src) {
96 int width = default_width;
97 int height = default_height;
98
99 // Get the plugin parameters from the attributes vector
100 for (unsigned i = 0; i < plugin_params_.attributeNames.size(); ++i) {
101 std::string attributeName = plugin_params_.attributeNames[i].utf8();
102 if (LowerCaseEqualsASCII(attributeName, "width")) {
103 std::string attributeValue = plugin_params_.attributeValues[i].utf8();
104 CHECK(base::StringToInt(attributeValue, &width));
105 } else if (LowerCaseEqualsASCII(attributeName, "height")) {
106 std::string attributeValue = plugin_params_.attributeValues[i].utf8();
107 CHECK(base::StringToInt(attributeValue, &height));
108 } else if (LowerCaseEqualsASCII(attributeName, "src")) {
109 src_ = plugin_params_.attributeValues[i].utf8();
110 }
111 }
112 // If we didn't find the attributes set or they're not sensible,
113 // we reset our attributes to the default.
114 if (src_.empty())
115 src_ = default_src;
116
117 size_.SetSize(width, height);
118 }
119
120 void BrowserPluginPlaceholder::GuestReady(
121 base::ProcessHandle process_handle,
122 const IPC::ChannelHandle& channel_handle) {
123 // TODO(fsamuel): Once the guest renderer is ready,
124 // it will inform the host renderer and the BrowserPluginPlaceholder
125 // can swap itself out with the guest.
126 NOTIMPLEMENTED();
127 }
128
129 void BrowserPluginPlaceholder::LoadGuest(WebKit::WebPlugin* new_plugin) {
130 WebKit::WebPluginContainer* container = plugin_->container();
131 if (!new_plugin || !new_plugin->initialize(container))
132 return;
133 plugin_->RestoreTitleText();
134 container->setPlugin(new_plugin);
135 container->invalidate();
136 container->reportGeometry();
137 plugin_->ReplayReceivedData(new_plugin);
138 plugin_->destroy();
139 }
140
141 void BrowserPluginPlaceholder::WillDestroyPlugin() {
142 delete this;
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698