| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/plugins/renderer/loadable_plugin_placeholder.h" | 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "content/public/child/v8_value_converter.h" | 15 #include "content/public/child/v8_value_converter.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
| 18 #include "content/public/renderer/render_thread.h" | 18 #include "content/public/renderer/render_thread.h" |
| 19 #include "gin/handle.h" | |
| 20 #include "gin/object_template_builder.h" | 19 #include "gin/object_template_builder.h" |
| 21 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" | 20 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
| 24 #include "third_party/WebKit/public/web/WebInputEvent.h" | 23 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 25 #include "third_party/WebKit/public/web/WebKit.h" | |
| 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 27 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 25 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 28 #include "third_party/WebKit/public/web/WebScriptSource.h" | 26 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 29 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" | 27 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 30 #include "third_party/WebKit/public/web/WebView.h" | 28 #include "third_party/WebKit/public/web/WebView.h" |
| 31 #include "third_party/re2/re2/re2.h" | 29 #include "third_party/re2/re2/re2.h" |
| 32 | 30 |
| 33 using base::UserMetricsAction; | 31 using base::UserMetricsAction; |
| 34 using blink::WebElement; | 32 using blink::WebElement; |
| 35 using blink::WebLocalFrame; | 33 using blink::WebLocalFrame; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); | 102 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); |
| 105 | 103 |
| 106 if (is_blocked_for_power_saver_poster_) { | 104 if (is_blocked_for_power_saver_poster_) { |
| 107 is_blocked_for_power_saver_poster_ = false; | 105 is_blocked_for_power_saver_poster_ = false; |
| 108 if (!LoadingBlocked()) | 106 if (!LoadingBlocked()) |
| 109 LoadPlugin(); | 107 LoadPlugin(); |
| 110 } | 108 } |
| 111 } | 109 } |
| 112 #endif | 110 #endif |
| 113 | 111 |
| 114 void LoadablePluginPlaceholder::BindWebFrame(blink::WebFrame* frame) { | |
| 115 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 116 v8::HandleScope handle_scope(isolate); | |
| 117 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | |
| 118 DCHECK(!context.IsEmpty()); | |
| 119 | |
| 120 v8::Context::Scope context_scope(context); | |
| 121 v8::Local<v8::Object> global = context->Global(); | |
| 122 global->Set(gin::StringToV8(isolate, "plugin"), | |
| 123 gin::CreateHandle(isolate, this).ToV8()); | |
| 124 } | |
| 125 | |
| 126 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( | 112 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( |
| 127 v8::Isolate* isolate) { | 113 v8::Isolate* isolate) { |
| 128 return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) | 114 return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) |
| 129 .SetMethod("load", &LoadablePluginPlaceholder::LoadCallback) | 115 .SetMethod("load", &LoadablePluginPlaceholder::LoadCallback) |
| 130 .SetMethod("hide", &LoadablePluginPlaceholder::HideCallback) | 116 .SetMethod("hide", &LoadablePluginPlaceholder::HideCallback) |
| 131 .SetMethod("didFinishLoading", | 117 .SetMethod("didFinishLoading", |
| 132 &LoadablePluginPlaceholder::DidFinishLoadingCallback); | 118 &LoadablePluginPlaceholder::DidFinishLoadingCallback); |
| 133 } | 119 } |
| 134 | 120 |
| 135 void LoadablePluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { | 121 void LoadablePluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 return identifier_; | 369 return identifier_; |
| 384 } | 370 } |
| 385 | 371 |
| 386 bool LoadablePluginPlaceholder::LoadingBlocked() const { | 372 bool LoadablePluginPlaceholder::LoadingBlocked() const { |
| 387 DCHECK(allow_loading_); | 373 DCHECK(allow_loading_); |
| 388 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 374 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
| 389 is_blocked_for_prerendering_; | 375 is_blocked_for_prerendering_; |
| 390 } | 376 } |
| 391 | 377 |
| 392 } // namespace plugins | 378 } // namespace plugins |
| OLD | NEW |