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

Side by Side Diff: components/plugins/renderer/mobile_youtube_plugin.cc

Issue 116163008: Move the plugin placeholder from CppBoundClass to gin::Wrappable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: counter-proposal Created 7 years 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 | Annotate | Revision Log
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 "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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Once we start seeing extra parameters we can return true. 66 // Once we start seeing extra parameters we can return true.
64 return c == '&' && i > len; 67 return c == '&' && i > len;
65 } 68 }
66 return true; 69 return true;
67 } 70 }
68 71
69 } // namespace 72 } // namespace
70 73
71 namespace plugins { 74 namespace plugins {
72 75
76 gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder(
77 v8::Isolate* isolate) {
78 return PluginPlaceholder::GetObjectTemplateBuilder(isolate)
79 .SetMethod("openYoutubeURL", &MobileYouTubePlugin::OpenYoutubeUrlCallback) ;
80 }
81
73 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderFrame* render_frame, 82 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderFrame* render_frame,
74 blink::WebFrame* frame, 83 blink::WebFrame* frame,
75 const blink::WebPluginParams& params, 84 const blink::WebPluginParams& params,
76 base::StringPiece& template_html, 85 base::StringPiece& template_html,
77 GURL placeholderDataUrl) 86 GURL placeholderDataUrl)
78 : PluginPlaceholder(render_frame, 87 : PluginPlaceholder(render_frame,
79 frame, 88 frame,
80 params, 89 params,
81 HtmlData(params, template_html), 90 HtmlData(params, template_html),
82 placeholderDataUrl) {} 91 placeholderDataUrl) {}
83 92
93 MobileYouTubePlugin::~MobileYouTubePlugin() {}
94
84 // static 95 // static
85 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, 96 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url,
86 const std::string& mime_type) { 97 const std::string& mime_type) {
87 std::string host = url.host(); 98 std::string host = url.host();
88 bool is_youtube = EndsWith(host, "youtube.com", true) || 99 bool is_youtube = EndsWith(host, "youtube.com", true) ||
89 EndsWith(host, "youtube-nocookie.com", true); 100 EndsWith(host, "youtube-nocookie.com", true);
90 101
91 return is_youtube && IsValidYouTubeVideo(url.path()) && 102 return is_youtube && IsValidYouTubeVideo(url.path()) &&
92 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); 103 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType);
93 } 104 }
94 105
95 void MobileYouTubePlugin::OpenYoutubeUrlCallback( 106 void MobileYouTubePlugin::OpenYoutubeUrlCallback() {
96 const webkit_glue::CppArgumentList& args,
97 webkit_glue::CppVariant* result) {
98 std::string youtube("vnd.youtube:"); 107 std::string youtube("vnd.youtube:");
99 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); 108 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams())));
100 WebURLRequest request; 109 WebURLRequest request;
101 request.initialize(); 110 request.initialize();
102 request.setURL(url); 111 request.setURL(url);
103 render_frame()->LoadURLExternally( 112 render_frame()->LoadURLExternally(
104 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); 113 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab);
105 } 114 }
115
106 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { 116 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) {
107 PluginPlaceholder::BindWebFrame(frame); 117 v8::Isolate* isolate = blink::mainThreadIsolate();
108 BindCallback("openYoutubeURL", 118 v8::HandleScope handle_scope(isolate);
109 base::Bind(&MobileYouTubePlugin::OpenYoutubeUrlCallback, 119 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
110 base::Unretained(this))); 120 DCHECK(!context.IsEmpty());
121
122 v8::Context::Scope context_scope(context);
123 v8::Handle<v8::Object> global = context->Global();
124 global->Set(gin::StringToV8(isolate, "plugin"),
125 gin::CreateHandle(isolate, this).ToV8());
111 } 126 }
112 127
113 } // namespace plugins 128 } // namespace plugins
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698