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

Side by Side Diff: components/translate/content/renderer/translate_helper.cc

Issue 2628053003: Remove extension group from DOMWrapperWorld. (Closed)
Patch Set: Fix GCCallbackTest Created 3 years, 11 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/translate/content/renderer/translate_helper.h" 5 #include "components/translate/content/renderer/translate_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 } // namespace 104 } // namespace
105 105
106 namespace translate { 106 namespace translate {
107 107
108 //////////////////////////////////////////////////////////////////////////////// 108 ////////////////////////////////////////////////////////////////////////////////
109 // TranslateHelper, public: 109 // TranslateHelper, public:
110 TranslateHelper::TranslateHelper(content::RenderFrame* render_frame, 110 TranslateHelper::TranslateHelper(content::RenderFrame* render_frame,
111 int world_id, 111 int world_id,
112 int extension_group,
113 const std::string& extension_scheme) 112 const std::string& extension_scheme)
114 : content::RenderFrameObserver(render_frame), 113 : content::RenderFrameObserver(render_frame),
115 world_id_(world_id), 114 world_id_(world_id),
116 extension_group_(extension_group),
117 extension_scheme_(extension_scheme), 115 extension_scheme_(extension_scheme),
118 binding_(this), 116 binding_(this),
119 weak_method_factory_(this) {} 117 weak_method_factory_(this) {}
120 118
121 TranslateHelper::~TranslateHelper() { 119 TranslateHelper::~TranslateHelper() {
122 } 120 }
123 121
124 void TranslateHelper::PrepareForUrl(const GURL& url) { 122 void TranslateHelper::PrepareForUrl(const GURL& url) {
125 // Navigated to a new url, reset current page translation. 123 // Navigated to a new url, reset current page translation.
126 ResetPage(); 124 ResetPage();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // Tests will override this function to return modified value. 229 // Tests will override this function to return modified value.
232 return base::TimeDelta::FromMilliseconds(delayInMs); 230 return base::TimeDelta::FromMilliseconds(delayInMs);
233 } 231 }
234 232
235 void TranslateHelper::ExecuteScript(const std::string& script) { 233 void TranslateHelper::ExecuteScript(const std::string& script) {
236 WebLocalFrame* main_frame = render_frame()->GetWebFrame(); 234 WebLocalFrame* main_frame = render_frame()->GetWebFrame();
237 if (!main_frame) 235 if (!main_frame)
238 return; 236 return;
239 237
240 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script)); 238 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
241 main_frame->executeScriptInIsolatedWorld( 239 main_frame->executeScriptInIsolatedWorld(world_id_, &source, 1);
242 world_id_, &source, 1, extension_group_);
243 } 240 }
244 241
245 bool TranslateHelper::ExecuteScriptAndGetBoolResult(const std::string& script, 242 bool TranslateHelper::ExecuteScriptAndGetBoolResult(const std::string& script,
246 bool fallback) { 243 bool fallback) {
247 WebLocalFrame* main_frame = render_frame()->GetWebFrame(); 244 WebLocalFrame* main_frame = render_frame()->GetWebFrame();
248 if (!main_frame) 245 if (!main_frame)
249 return fallback; 246 return fallback;
250 247
251 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 248 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
252 WebVector<v8::Local<v8::Value> > results; 249 WebVector<v8::Local<v8::Value> > results;
253 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script)); 250 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
254 main_frame->executeScriptInIsolatedWorld( 251 main_frame->executeScriptInIsolatedWorld(world_id_, &source, 1, &results);
255 world_id_, &source, 1, extension_group_, &results);
256 if (results.size() != 1 || results[0].IsEmpty() || !results[0]->IsBoolean()) { 252 if (results.size() != 1 || results[0].IsEmpty() || !results[0]->IsBoolean()) {
257 NOTREACHED(); 253 NOTREACHED();
258 return fallback; 254 return fallback;
259 } 255 }
260 256
261 return results[0]->BooleanValue(); 257 return results[0]->BooleanValue();
262 } 258 }
263 259
264 std::string TranslateHelper::ExecuteScriptAndGetStringResult( 260 std::string TranslateHelper::ExecuteScriptAndGetStringResult(
265 const std::string& script) { 261 const std::string& script) {
266 WebLocalFrame* main_frame = render_frame()->GetWebFrame(); 262 WebLocalFrame* main_frame = render_frame()->GetWebFrame();
267 if (!main_frame) 263 if (!main_frame)
268 return std::string(); 264 return std::string();
269 265
270 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 266 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
271 WebVector<v8::Local<v8::Value> > results; 267 WebVector<v8::Local<v8::Value> > results;
272 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script)); 268 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
273 main_frame->executeScriptInIsolatedWorld( 269 main_frame->executeScriptInIsolatedWorld(world_id_, &source, 1, &results);
274 world_id_, &source, 1, extension_group_, &results);
275 if (results.size() != 1 || results[0].IsEmpty() || !results[0]->IsString()) { 270 if (results.size() != 1 || results[0].IsEmpty() || !results[0]->IsString()) {
276 NOTREACHED(); 271 NOTREACHED();
277 return std::string(); 272 return std::string();
278 } 273 }
279 274
280 v8::Local<v8::String> v8_str = results[0].As<v8::String>(); 275 v8::Local<v8::String> v8_str = results[0].As<v8::String>();
281 int length = v8_str->Utf8Length() + 1; 276 int length = v8_str->Utf8Length() + 1;
282 std::unique_ptr<char[]> str(new char[length]); 277 std::unique_ptr<char[]> str(new char[length]);
283 v8_str->WriteUtf8(str.get(), length); 278 v8_str->WriteUtf8(str.get(), length);
284 return std::string(str.get()); 279 return std::string(str.get());
285 } 280 }
286 281
287 double TranslateHelper::ExecuteScriptAndGetDoubleResult( 282 double TranslateHelper::ExecuteScriptAndGetDoubleResult(
288 const std::string& script) { 283 const std::string& script) {
289 WebLocalFrame* main_frame = render_frame()->GetWebFrame(); 284 WebLocalFrame* main_frame = render_frame()->GetWebFrame();
290 if (!main_frame) 285 if (!main_frame)
291 return 0.0; 286 return 0.0;
292 287
293 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 288 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
294 WebVector<v8::Local<v8::Value> > results; 289 WebVector<v8::Local<v8::Value> > results;
295 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script)); 290 WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
296 main_frame->executeScriptInIsolatedWorld( 291 main_frame->executeScriptInIsolatedWorld(world_id_, &source, 1, &results);
297 world_id_, &source, 1, extension_group_, &results);
298 if (results.size() != 1 || results[0].IsEmpty() || !results[0]->IsNumber()) { 292 if (results.size() != 1 || results[0].IsEmpty() || !results[0]->IsNumber()) {
299 NOTREACHED(); 293 NOTREACHED();
300 return 0.0; 294 return 0.0;
301 } 295 }
302 296
303 return results[0]->NumberValue(); 297 return results[0]->NumberValue();
304 } 298 }
305 299
306 // mojom::Page implementations. 300 // mojom::Page implementations.
307 void TranslateHelper::Translate(const std::string& translate_script, 301 void TranslateHelper::Translate(const std::string& translate_script,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 binding_.Close(); 468 binding_.Close();
475 translate_callback_pending_.Reset(); 469 translate_callback_pending_.Reset();
476 CancelPendingTranslation(); 470 CancelPendingTranslation();
477 } 471 }
478 472
479 void TranslateHelper::OnDestruct() { 473 void TranslateHelper::OnDestruct() {
480 delete this; 474 delete this;
481 } 475 }
482 476
483 } // namespace translate 477 } // namespace translate
OLDNEW
« no previous file with comments | « components/translate/content/renderer/translate_helper.h ('k') | content/public/renderer/render_frame_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698