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

Side by Side Diff: chrome/renderer/contextualsearch/contextual_search_wrapper.cc

Issue 1385663002: [Contextual Search] Add Mojo-enabled API component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Kausalya's comments, added TODO and bug reference for transition from JS to a better way. Created 5 years, 2 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/contextualsearch/contextual_search_wrapper.h"
6
7 #include "base/strings/string_util.h"
8 #include "gin/arguments.h"
9 #include "gin/handle.h"
10 #include "gin/object_template_builder.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
12 #include "third_party/WebKit/public/web/WebKit.h"
13 #include "v8/include/v8.h"
14
15 namespace search {
16
17 static const char kContextualSearchObjectName[] = "contextualSearch";
18 static const char kSetCaptionMethodName[] = "setCaption";
19
20 // TODO(donnd): merge with the identical code in
21 // chrome_object_extensions_utils (which chrome-android can't access).
22 v8::Local<v8::Object> GetOrCreateChromeObject(v8::Isolate* isolate,
jochen (gone - plz use gerrit) 2015/10/20 08:09:56 I'd move this to content/public/renderer/chrome_ob
Donn Denman 2015/10/20 21:56:46 I tried this, but I couldn't get it to link, so I'
23 v8::Local<v8::Object> global) {
24 v8::Local<v8::Object> chrome;
25 v8::Local<v8::Value> chrome_value =
26 global->Get(gin::StringToV8(isolate, "chrome"));
27 if (chrome_value.IsEmpty() || !chrome_value->IsObject()) {
28 chrome = v8::Object::New(isolate);
29 global->Set(gin::StringToSymbol(isolate, "chrome"), chrome);
30 } else {
31 chrome = v8::Local<v8::Object>::Cast(chrome_value);
32 }
33 return chrome;
34 }
35
36 gin::WrapperInfo ContextualSearchWrapper::kWrapperInfo = {
37 gin::kEmbedderNativeGin};
38
39 // static
40 void ContextualSearchWrapper::Install(blink::WebFrame* frame) {
41 // NOTE: Installing new v8 functions that can access Chrome native code
42 // requires a security review! We did an exahustive search for a better
43 // way to implement a communication channel between the page and Chrome,
44 // but found nothing better.
45 // TODO(donnd): use a better communication channel once that becomes
46 // available, e.g. navigator.connect API. See crbug.com/541683.
47 // TODO(donnd): refactor some of this boilerplate into a reusable
48 // method. This was cribbed from MemoryBenchmarkingExtension.
49 v8::Isolate* isolate = blink::mainThreadIsolate();
50 v8::HandleScope handle_scope(isolate);
51 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
52 if (context.IsEmpty())
53 return;
54
55 v8::Context::Scope context_scope(context);
56 gin::Handle<ContextualSearchWrapper> wrapper =
57 gin::CreateHandle(isolate, new ContextualSearchWrapper());
58 if (wrapper.IsEmpty())
59 return;
60
61 v8::Local<v8::Object> chrome =
62 GetOrCreateChromeObject(isolate, context->Global());
63 chrome->Set(gin::StringToV8(isolate, kContextualSearchObjectName),
64 wrapper.ToV8());
65 }
66
67 ContextualSearchWrapper::ContextualSearchWrapper() {}
68
69 ContextualSearchWrapper::~ContextualSearchWrapper() {}
70
71 gin::ObjectTemplateBuilder ContextualSearchWrapper::GetObjectTemplateBuilder(
72 v8::Isolate* isolate) {
73 return gin::Wrappable<ContextualSearchWrapper>::GetObjectTemplateBuilder(
74 isolate)
75 .SetMethod(kSetCaptionMethodName, &ContextualSearchWrapper::SetCaption);
76 }
77
78 // static
79 void ContextualSearchWrapper::SetCaption(const std::string& caption) {
80 DVLOG(0) << "ctxs SetCaption: caption: " << caption;
81 // TODO(donnd): send the caption to the Browser!
82 }
83
84 } // namespace search
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698