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 "third_party/WebKit/public/web/WebFrame.h" | 16 #include "third_party/WebKit/public/web/WebFrame.h" |
| 17 #include "third_party/WebKit/public/web/WebKit.h" |
15 #include "ui/base/webui/jstemplate_builder.h" | 18 #include "ui/base/webui/jstemplate_builder.h" |
16 | 19 |
17 using blink::WebFrame; | 20 using blink::WebFrame; |
18 using blink::WebPlugin; | 21 using blink::WebPlugin; |
19 using blink::WebURLRequest; | 22 using blink::WebURLRequest; |
20 | 23 |
21 const char* const kSlashVSlash = "/v/"; | 24 const char* const kSlashVSlash = "/v/"; |
22 const char* const kSlashESlash = "/e/"; | 25 const char* const kSlashESlash = "/e/"; |
23 | 26 |
24 namespace { | 27 namespace { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 blink::WebFrame* frame, | 77 blink::WebFrame* frame, |
75 const blink::WebPluginParams& params, | 78 const blink::WebPluginParams& params, |
76 base::StringPiece& template_html, | 79 base::StringPiece& template_html, |
77 GURL placeholderDataUrl) | 80 GURL placeholderDataUrl) |
78 : PluginPlaceholder(render_frame, | 81 : PluginPlaceholder(render_frame, |
79 frame, | 82 frame, |
80 params, | 83 params, |
81 HtmlData(params, template_html), | 84 HtmlData(params, template_html), |
82 placeholderDataUrl) {} | 85 placeholderDataUrl) {} |
83 | 86 |
| 87 MobileYouTubePlugin::~MobileYouTubePlugin() {} |
| 88 |
84 // static | 89 // static |
85 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, | 90 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, |
86 const std::string& mime_type) { | 91 const std::string& mime_type) { |
87 std::string host = url.host(); | 92 std::string host = url.host(); |
88 bool is_youtube = EndsWith(host, "youtube.com", true) || | 93 bool is_youtube = EndsWith(host, "youtube.com", true) || |
89 EndsWith(host, "youtube-nocookie.com", true); | 94 EndsWith(host, "youtube-nocookie.com", true); |
90 | 95 |
91 return is_youtube && IsValidYouTubeVideo(url.path()) && | 96 return is_youtube && IsValidYouTubeVideo(url.path()) && |
92 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); | 97 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); |
93 } | 98 } |
94 | 99 |
95 void MobileYouTubePlugin::OpenYoutubeUrlCallback( | 100 void MobileYouTubePlugin::OpenYoutubeUrlCallback() { |
96 const webkit_glue::CppArgumentList& args, | |
97 webkit_glue::CppVariant* result) { | |
98 std::string youtube("vnd.youtube:"); | 101 std::string youtube("vnd.youtube:"); |
99 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); | 102 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); |
100 WebURLRequest request; | 103 WebURLRequest request; |
101 request.initialize(); | 104 request.initialize(); |
102 request.setURL(url); | 105 request.setURL(url); |
103 render_frame()->LoadURLExternally( | 106 render_frame()->LoadURLExternally( |
104 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); | 107 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); |
105 } | 108 } |
| 109 |
106 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { | 110 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { |
107 PluginPlaceholder::BindWebFrame(frame); | 111 v8::Isolate* isolate = blink::mainThreadIsolate(); |
108 BindCallback("openYoutubeURL", | 112 v8::HandleScope handle_scope(isolate); |
109 base::Bind(&MobileYouTubePlugin::OpenYoutubeUrlCallback, | 113 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
110 base::Unretained(this))); | 114 DCHECK(!context.IsEmpty()); |
| 115 |
| 116 v8::Context::Scope context_scope(context); |
| 117 v8::Handle<v8::Object> global = context->Global(); |
| 118 global->Set(gin::StringToV8(isolate, "plugin"), |
| 119 gin::CreateHandle(isolate, this).ToV8()); |
| 120 } |
| 121 |
| 122 gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( |
| 123 v8::Isolate* isolate) { |
| 124 return PluginPlaceholder::GetObjectTemplateBuilder(isolate) |
| 125 .SetMethod("openYoutubeURL", &MobileYouTubePlugin::OpenYoutubeUrlCallback); |
111 } | 126 } |
112 | 127 |
113 } // namespace plugins | 128 } // namespace plugins |
OLD | NEW |