| OLD | NEW |
| 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 "components/plugins/renderer/mobile_youtube_plugin.h" | 5 #include "components/plugins/renderer/mobile_youtube_plugin.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/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "content/public/common/content_constants.h" | 12 #include "content/public/common/content_constants.h" |
| 13 #include "content/public/renderer/render_frame.h" | 13 #include "content/public/renderer/render_frame.h" |
| 14 #include "gin/handle.h" | |
| 15 #include "gin/object_template_builder.h" | 14 #include "gin/object_template_builder.h" |
| 16 #include "third_party/WebKit/public/web/WebFrame.h" | 15 #include "third_party/WebKit/public/web/WebFrame.h" |
| 17 #include "third_party/WebKit/public/web/WebKit.h" | |
| 18 #include "ui/base/webui/jstemplate_builder.h" | 16 #include "ui/base/webui/jstemplate_builder.h" |
| 19 | 17 |
| 20 using blink::WebFrame; | 18 using blink::WebFrame; |
| 21 using blink::WebPlugin; | 19 using blink::WebPlugin; |
| 22 using blink::WebURLRequest; | 20 using blink::WebURLRequest; |
| 23 | 21 |
| 24 const char* const kSlashVSlash = "/v/"; | 22 const char* const kSlashVSlash = "/v/"; |
| 25 const char* const kSlashESlash = "/e/"; | 23 const char* const kSlashESlash = "/e/"; |
| 26 | 24 |
| 27 namespace { | 25 namespace { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Once we start seeing extra parameters we can return true. | 64 // Once we start seeing extra parameters we can return true. |
| 67 return c == '&' && i > len; | 65 return c == '&' && i > len; |
| 68 } | 66 } |
| 69 return true; | 67 return true; |
| 70 } | 68 } |
| 71 | 69 |
| 72 } // namespace | 70 } // namespace |
| 73 | 71 |
| 74 namespace plugins { | 72 namespace plugins { |
| 75 | 73 |
| 74 gin::WrapperInfo MobileYouTubePlugin::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 75 |
| 76 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderFrame* render_frame, | 76 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderFrame* render_frame, |
| 77 blink::WebLocalFrame* frame, | 77 blink::WebLocalFrame* frame, |
| 78 const blink::WebPluginParams& params, | 78 const blink::WebPluginParams& params, |
| 79 base::StringPiece& template_html, | 79 base::StringPiece& template_html) |
| 80 GURL placeholderDataUrl) | 80 : PluginPlaceholderBase(render_frame, |
| 81 : PluginPlaceholder(render_frame, | 81 frame, |
| 82 frame, | 82 params, |
| 83 params, | 83 HtmlData(params, template_html)) { |
| 84 HtmlData(params, template_html), | 84 } |
| 85 placeholderDataUrl) {} | |
| 86 | 85 |
| 87 MobileYouTubePlugin::~MobileYouTubePlugin() {} | 86 MobileYouTubePlugin::~MobileYouTubePlugin() {} |
| 88 | 87 |
| 89 // static | 88 // static |
| 90 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, | 89 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, |
| 91 const std::string& mime_type) { | 90 const std::string& mime_type) { |
| 92 std::string host = url.host(); | 91 std::string host = url.host(); |
| 93 bool is_youtube = EndsWith(host, "youtube.com", true) || | 92 bool is_youtube = EndsWith(host, "youtube.com", true) || |
| 94 EndsWith(host, "youtube-nocookie.com", true); | 93 EndsWith(host, "youtube-nocookie.com", true); |
| 95 | 94 |
| 96 return is_youtube && IsValidYouTubeVideo(url.path()) && | 95 return is_youtube && IsValidYouTubeVideo(url.path()) && |
| 97 base::LowerCaseEqualsASCII(mime_type, | 96 base::LowerCaseEqualsASCII(mime_type, |
| 98 content::kFlashPluginSwfMimeType); | 97 content::kFlashPluginSwfMimeType); |
| 99 } | 98 } |
| 100 | 99 |
| 101 void MobileYouTubePlugin::OpenYoutubeUrlCallback() { | 100 void MobileYouTubePlugin::OpenYoutubeUrlCallback() { |
| 102 std::string youtube("vnd.youtube:"); | 101 std::string youtube("vnd.youtube:"); |
| 103 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); | 102 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); |
| 104 WebURLRequest request; | 103 WebURLRequest request; |
| 105 request.initialize(); | 104 request.initialize(); |
| 106 request.setURL(url); | 105 request.setURL(url); |
| 107 render_frame()->LoadURLExternally( | 106 render_frame()->LoadURLExternally( |
| 108 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); | 107 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { | 110 v8::Local<v8::Value> MobileYouTubePlugin::GetV8Handle(v8::Isolate* isolate) { |
| 112 v8::Isolate* isolate = blink::mainThreadIsolate(); | 111 return gin::CreateHandle(isolate, this).ToV8(); |
| 113 v8::HandleScope handle_scope(isolate); | |
| 114 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | |
| 115 DCHECK(!context.IsEmpty()); | |
| 116 | |
| 117 v8::Context::Scope context_scope(context); | |
| 118 v8::Local<v8::Object> global = context->Global(); | |
| 119 global->Set(gin::StringToV8(isolate, "plugin"), | |
| 120 gin::CreateHandle(isolate, this).ToV8()); | |
| 121 } | 112 } |
| 122 | 113 |
| 123 gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( | 114 gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( |
| 124 v8::Isolate* isolate) { | 115 v8::Isolate* isolate) { |
| 125 return PluginPlaceholder::GetObjectTemplateBuilder(isolate) | 116 return gin::Wrappable<MobileYouTubePlugin>::GetObjectTemplateBuilder(isolate) |
| 126 .SetMethod("openYoutubeURL", &MobileYouTubePlugin::OpenYoutubeUrlCallback); | 117 .SetMethod("openYoutubeURL", |
| 118 &MobileYouTubePlugin::OpenYoutubeUrlCallback); |
| 127 } | 119 } |
| 128 | 120 |
| 129 } // namespace plugins | 121 } // namespace plugins |
| OLD | NEW |