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

Side by Side Diff: extensions/renderer/user_script_injector.cc

Issue 2258183003: Make GreasemonkeyApiJsString truly singleton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments + sync Created 4 years, 3 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 | « no previous file | 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/user_script_injector.h" 5 #include "extensions/renderer/user_script_injector.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // |script_id| and |routing_id| pair. 58 // |script_id| and |routing_id| pair.
59 base::LazyInstance<RoutingInfoMap> g_routing_info_map = 59 base::LazyInstance<RoutingInfoMap> g_routing_info_map =
60 LAZY_INSTANCE_INITIALIZER; 60 LAZY_INSTANCE_INITIALIZER;
61 61
62 // Greasemonkey API source that is injected with the scripts. 62 // Greasemonkey API source that is injected with the scripts.
63 struct GreasemonkeyApiJsString { 63 struct GreasemonkeyApiJsString {
64 GreasemonkeyApiJsString(); 64 GreasemonkeyApiJsString();
65 blink::WebScriptSource GetSource() const; 65 blink::WebScriptSource GetSource() const;
66 66
67 private: 67 private:
68 std::string source_; 68 blink::WebString source_;
69 }; 69 };
70 70
71 // The below constructor, monstrous as it is, just makes a WebScriptSource from 71 // The below constructor, monstrous as it is, just makes a WebScriptSource from
72 // the GreasemonkeyApiJs resource. 72 // the GreasemonkeyApiJs resource.
73 GreasemonkeyApiJsString::GreasemonkeyApiJsString() 73 GreasemonkeyApiJsString::GreasemonkeyApiJsString() {
74 : source_(ResourceBundle::GetSharedInstance() 74 base::StringPiece source_piece =
75 .GetRawDataResource(IDR_GREASEMONKEY_API_JS) 75 ResourceBundle::GetSharedInstance().GetRawDataResource(
76 .as_string()) { 76 IDR_GREASEMONKEY_API_JS);
77 source_ =
78 blink::WebString::fromUTF8(source_piece.data(), source_piece.length());
77 } 79 }
78 80
79 blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const { 81 blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const {
80 return blink::WebScriptSource(blink::WebString::fromUTF8(source_)); 82 return blink::WebScriptSource(source_);
81 } 83 }
82 84
83 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api = 85 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api =
84 LAZY_INSTANCE_INITIALIZER; 86 LAZY_INSTANCE_INITIALIZER;
85 87
86 } // namespace 88 } // namespace
87 89
88 UserScriptInjector::UserScriptInjector(const UserScript* script, 90 UserScriptInjector::UserScriptInjector(const UserScript* script,
89 UserScriptSet* script_list, 91 UserScriptSet* script_list,
90 bool is_declarative) 92 bool is_declarative)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 void UserScriptInjector::OnInjectionComplete( 281 void UserScriptInjector::OnInjectionComplete(
280 std::unique_ptr<base::Value> execution_result, 282 std::unique_ptr<base::Value> execution_result,
281 UserScript::RunLocation run_location, 283 UserScript::RunLocation run_location,
282 content::RenderFrame* render_frame) {} 284 content::RenderFrame* render_frame) {}
283 285
284 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason, 286 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason,
285 content::RenderFrame* render_frame) { 287 content::RenderFrame* render_frame) {
286 } 288 }
287 289
288 } // namespace extensions 290 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698