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" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderView* render_view, | 73 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderView* render_view, |
74 blink::WebFrame* frame, | 74 blink::WebFrame* frame, |
75 const blink::WebPluginParams& params, | 75 const blink::WebPluginParams& params, |
76 base::StringPiece& template_html, | 76 base::StringPiece& template_html, |
77 GURL placeholderDataUrl) | 77 GURL placeholderDataUrl) |
78 : PluginPlaceholder(render_view, | 78 : PluginPlaceholder(render_view, |
79 frame, | 79 frame, |
80 params, | 80 params, |
81 HtmlData(params, template_html), | 81 HtmlData(params, template_html), |
82 placeholderDataUrl) {} | 82 placeholderDataUrl) { |
| 83 RegisterCallback("openYoutubeURL"); |
| 84 } |
83 | 85 |
84 // static | 86 // static |
85 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, | 87 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, |
86 const std::string& mime_type) { | 88 const std::string& mime_type) { |
87 std::string host = url.host(); | 89 std::string host = url.host(); |
88 bool is_youtube = EndsWith(host, "youtube.com", true) || | 90 bool is_youtube = EndsWith(host, "youtube.com", true) || |
89 EndsWith(host, "youtube-nocookie.com", true); | 91 EndsWith(host, "youtube-nocookie.com", true); |
90 | 92 |
91 return is_youtube && IsValidYouTubeVideo(url.path()) && | 93 return is_youtube && IsValidYouTubeVideo(url.path()) && |
92 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); | 94 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); |
93 } | 95 } |
94 | 96 |
95 void MobileYouTubePlugin::OpenYoutubeUrlCallback( | 97 void MobileYouTubePlugin::Observe(const std::string& callback) { |
96 const webkit_glue::CppArgumentList& args, | 98 DCHECK_EQ("openYoutubeURL", callback); |
97 webkit_glue::CppVariant* result) { | 99 |
98 std::string youtube("vnd.youtube:"); | 100 std::string youtube("vnd.youtube:"); |
99 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); | 101 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); |
100 WebURLRequest request; | 102 WebURLRequest request; |
101 request.initialize(); | 103 request.initialize(); |
102 request.setURL(url); | 104 request.setURL(url); |
103 render_view()->LoadURLExternally( | 105 render_view()->LoadURLExternally( |
104 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); | 106 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); |
105 } | 107 } |
106 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { | |
107 PluginPlaceholder::BindWebFrame(frame); | |
108 BindCallback("openYoutubeURL", | |
109 base::Bind(&MobileYouTubePlugin::OpenYoutubeUrlCallback, | |
110 base::Unretained(this))); | |
111 } | |
112 | 108 |
113 } // namespace plugins | 109 } // namespace plugins |
OLD | NEW |