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

Side by Side Diff: chrome/renderer/plugins/chrome_plugin_placeholder.cc

Issue 981623003: Plugin Power Saver: Implement srcset syntax for posters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" 5 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/common/prerender_messages.h" 9 #include "chrome/common/prerender_messages.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // The placeholder is loaded in normal web renderer processes, so it should not 49 // The placeholder is loaded in normal web renderer processes, so it should not
50 // have a chrome:// scheme that might let it be confused with a WebUI page. 50 // have a chrome:// scheme that might let it be confused with a WebUI page.
51 const char ChromePluginPlaceholder::kPluginPlaceholderDataURL[] = 51 const char ChromePluginPlaceholder::kPluginPlaceholderDataURL[] =
52 "data:text/html,pluginplaceholderdata"; 52 "data:text/html,pluginplaceholderdata";
53 53
54 ChromePluginPlaceholder::ChromePluginPlaceholder( 54 ChromePluginPlaceholder::ChromePluginPlaceholder(
55 content::RenderFrame* render_frame, 55 content::RenderFrame* render_frame,
56 blink::WebLocalFrame* frame, 56 blink::WebLocalFrame* frame,
57 const blink::WebPluginParams& params, 57 const blink::WebPluginParams& params,
58 const std::string& html_data, 58 const std::string& html_data,
59 const base::string16& title) 59 const base::string16& title,
60 const GURL& placeholder_url)
60 : plugins::LoadablePluginPlaceholder(render_frame, 61 : plugins::LoadablePluginPlaceholder(render_frame,
61 frame, 62 frame,
62 params, 63 params,
63 html_data, 64 html_data,
64 GURL(kPluginPlaceholderDataURL)), 65 placeholder_url),
65 status_(new ChromeViewHostMsg_GetPluginInfo_Status), 66 status_(new ChromeViewHostMsg_GetPluginInfo_Status),
66 title_(title), 67 title_(title),
67 #if defined(ENABLE_PLUGIN_INSTALLATION) 68 #if defined(ENABLE_PLUGIN_INSTALLATION)
68 placeholder_routing_id_(MSG_ROUTING_NONE), 69 placeholder_routing_id_(MSG_ROUTING_NONE),
69 #endif 70 #endif
70 has_host_(false), 71 has_host_(false),
71 context_menu_request_id_(0) { 72 context_menu_request_id_(0) {
72 RenderThread::Get()->AddObserver(this); 73 RenderThread::Get()->AddObserver(this);
73 } 74 }
74 75
(...skipping 27 matching lines...) Expand all
102 values.SetString("message", l10n_util::GetStringUTF8(IDS_PLUGIN_SEARCHING)); 103 values.SetString("message", l10n_util::GetStringUTF8(IDS_PLUGIN_SEARCHING));
103 #else 104 #else
104 values.SetString("message", 105 values.SetString("message",
105 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED)); 106 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED));
106 #endif 107 #endif
107 108
108 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 109 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
109 110
110 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. 111 // |missing_plugin| will destroy itself when its WebViewPlugin is going away.
111 ChromePluginPlaceholder* missing_plugin = new ChromePluginPlaceholder( 112 ChromePluginPlaceholder* missing_plugin = new ChromePluginPlaceholder(
112 render_frame, frame, params, html_data, params.mimeType); 113 render_frame, frame, params, html_data, params.mimeType,
114 GURL(kPluginPlaceholderDataURL));
113 missing_plugin->set_allow_loading(true); 115 missing_plugin->set_allow_loading(true);
114 #if defined(ENABLE_PLUGIN_INSTALLATION) 116 #if defined(ENABLE_PLUGIN_INSTALLATION)
115 RenderThread::Get()->Send( 117 RenderThread::Get()->Send(
116 new ChromeViewHostMsg_FindMissingPlugin(missing_plugin->routing_id(), 118 new ChromeViewHostMsg_FindMissingPlugin(missing_plugin->routing_id(),
117 missing_plugin->CreateRoutingId(), 119 missing_plugin->CreateRoutingId(),
118 params.mimeType.utf8())); 120 params.mimeType.utf8()));
119 #endif 121 #endif
120 return missing_plugin; 122 return missing_plugin;
121 } 123 }
122 124
123 // static 125 // static
124 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateErrorPlugin( 126 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateErrorPlugin(
125 content::RenderFrame* render_frame, 127 content::RenderFrame* render_frame,
126 const base::FilePath& file_path) { 128 const base::FilePath& file_path) {
127 base::DictionaryValue values; 129 base::DictionaryValue values;
128 values.SetString("message", 130 values.SetString("message",
129 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR)); 131 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR));
130 132
131 const base::StringPiece template_html( 133 const base::StringPiece template_html(
132 ResourceBundle::GetSharedInstance().GetRawDataResource( 134 ResourceBundle::GetSharedInstance().GetRawDataResource(
133 IDR_BLOCKED_PLUGIN_HTML)); 135 IDR_BLOCKED_PLUGIN_HTML));
134 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 136 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
135 137
136 WebPluginParams params; 138 WebPluginParams params;
137 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. 139 // |missing_plugin| will destroy itself when its WebViewPlugin is going away.
138 ChromePluginPlaceholder* plugin = new ChromePluginPlaceholder( 140 ChromePluginPlaceholder* plugin = new ChromePluginPlaceholder(
139 render_frame, NULL, params, html_data, params.mimeType); 141 render_frame, NULL, params, html_data, params.mimeType,
142 GURL(kPluginPlaceholderDataURL));
140 143
141 RenderThread::Get()->Send(new ChromeViewHostMsg_CouldNotLoadPlugin( 144 RenderThread::Get()->Send(new ChromeViewHostMsg_CouldNotLoadPlugin(
142 plugin->routing_id(), file_path)); 145 plugin->routing_id(), file_path));
143 return plugin; 146 return plugin;
144 } 147 }
145 148
146 // static 149 // static
147 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( 150 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin(
148 content::RenderFrame* render_frame, 151 content::RenderFrame* render_frame,
149 WebLocalFrame* frame, 152 WebLocalFrame* frame,
150 const WebPluginParams& params, 153 const WebPluginParams& params,
151 const content::WebPluginInfo& info, 154 const content::WebPluginInfo& info,
152 const std::string& identifier, 155 const std::string& identifier,
153 const base::string16& name, 156 const base::string16& name,
154 int template_id, 157 int template_id,
155 const base::string16& message, 158 const base::string16& message,
156 const GURL& poster_url) { 159 const std::string& poster_attribute,
160 const GURL& placeholder_url) {
157 base::DictionaryValue values; 161 base::DictionaryValue values;
158 values.SetString("message", message); 162 values.SetString("message", message);
159 values.SetString("name", name); 163 values.SetString("name", name);
160 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); 164 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE));
161 165
162 if (poster_url.is_valid()) 166 if (!poster_attribute.empty())
163 values.SetString("background", "url('" + poster_url.spec() + "')"); 167 values.SetString("poster", poster_attribute);
164 168
165 const base::StringPiece template_html( 169 const base::StringPiece template_html(
166 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 170 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
167 171
168 DCHECK(!template_html.empty()) << "unable to load template. ID: " 172 DCHECK(!template_html.empty()) << "unable to load template. ID: "
169 << template_id; 173 << template_id;
170 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 174 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
171 175
172 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. 176 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away.
173 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( 177 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder(
174 render_frame, frame, params, html_data, name); 178 render_frame, frame, params, html_data, name,
179 placeholder_url.is_valid() ? placeholder_url
tommycli 2015/03/04 19:55:17 Needs some security scrutiny: In order to allow r
Bernhard Bauer 2015/03/05 09:12:51 Could you just set a <base> tag in the header? Tha
tommycli 2015/03/05 19:49:12 That totally worked! You guys are smarter than me!
180 : GURL(kPluginPlaceholderDataURL));
175 181
176 #if defined(ENABLE_PLUGINS) 182 #if defined(ENABLE_PLUGINS)
177 if (poster_url.is_valid()) 183 if (!poster_attribute.empty())
178 blocked_plugin->BlockForPowerSaverPoster(); 184 blocked_plugin->BlockForPowerSaverPoster();
179 #endif 185 #endif
180 blocked_plugin->SetPluginInfo(info); 186 blocked_plugin->SetPluginInfo(info);
181 blocked_plugin->SetIdentifier(identifier); 187 blocked_plugin->SetIdentifier(identifier);
182 return blocked_plugin; 188 return blocked_plugin;
183 } 189 }
184 190
185 void ChromePluginPlaceholder::SetStatus( 191 void ChromePluginPlaceholder::SetStatus(
186 const ChromeViewHostMsg_GetPluginInfo_Status& status) { 192 const ChromeViewHostMsg_GetPluginInfo_Status& status) {
187 status_->value = status.value; 193 status_->value = status.value;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 v8::Handle<v8::Object> global = context->Global(); 380 v8::Handle<v8::Object> global = context->Global();
375 global->Set(gin::StringToV8(isolate, "plugin"), 381 global->Set(gin::StringToV8(isolate, "plugin"),
376 gin::CreateHandle(isolate, this).ToV8()); 382 gin::CreateHandle(isolate, this).ToV8());
377 } 383 }
378 384
379 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( 385 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder(
380 v8::Isolate* isolate) { 386 v8::Isolate* isolate) {
381 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod( 387 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod(
382 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback); 388 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback);
383 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698