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

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: Simplify to only track one Renderer process ID. Rebase. 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
« no previous file with comments | « chrome/renderer/contextualsearch/contextual_search_wrapper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
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 // TODO(donnd): refactor some of this boilerplate into a reusable
42 // method. This was cribbed from MemoryBenchmarkingExtension.
43 v8::Isolate* isolate = blink::mainThreadIsolate();
44 v8::HandleScope handle_scope(isolate);
45 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
46 if (context.IsEmpty())
47 return;
48
49 v8::Context::Scope context_scope(context);
50 gin::Handle<ContextualSearchWrapper> wrapper =
51 gin::CreateHandle(isolate, new ContextualSearchWrapper());
52 if (wrapper.IsEmpty())
53 return;
54
55 v8::Local<v8::Object> chrome =
56 GetOrCreateChromeObject(isolate, context->Global());
57 chrome->Set(gin::StringToV8(isolate, kContextualSearchObjectName),
58 wrapper.ToV8());
59 }
60
61 ContextualSearchWrapper::ContextualSearchWrapper() {}
62
63 ContextualSearchWrapper::~ContextualSearchWrapper() {}
64
65 gin::ObjectTemplateBuilder ContextualSearchWrapper::GetObjectTemplateBuilder(
66 v8::Isolate* isolate) {
67 return gin::Wrappable<ContextualSearchWrapper>::GetObjectTemplateBuilder(
68 isolate)
69 .SetMethod(kSetCaptionMethodName, &ContextualSearchWrapper::SetCaption);
70 }
71
72 // static
73 void ContextualSearchWrapper::SetCaption(gin::Arguments* args) {
jochen (gone - plz use gerrit) 2015/10/07 13:49:25 just use SetCaption(const std::string& caption) -
Donn Denman 2015/10/07 19:33:11 Done.
74 // Need a string argument.
75 std::string caption;
76 if (args->Length() == 1 && args->PeekNext()->IsString()) {
77 args->GetNext(&caption);
78 } else {
79 args->ThrowTypeError("Exactly one String argument is required.");
80 return;
81 }
82
83 DVLOG(0) << "ctxs SetCaption: caption: " << caption;
84 // TODO(donnd): send the caption to the Browser!
85 }
86
87 } // namespace search
OLDNEW
« no previous file with comments | « chrome/renderer/contextualsearch/contextual_search_wrapper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698