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

Unified Diff: extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher_group.cc

Issue 1056533002: Implement <webview>.addContentScript/removeContentScript API [2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webview_addremove_contentscripts_2
Patch Set: Fix a test. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher_group.cc
diff --git a/extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher_group.cc b/extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher_group.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9431582fe4a9cd659f4868219d6606bda288f371
--- /dev/null
+++ b/extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher_group.cc
@@ -0,0 +1,51 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/string_util.h"
+#include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher_group.h"
+
+WebUIURLFetcherGroup::WebUIURLFetcherGroup(content::BrowserContext* context,
+ const base::Closure& callback)
+ : context_(context), complete_fetchers_(0), callback_(callback) {
+}
+
+WebUIURLFetcherGroup::~WebUIURLFetcherGroup() {
+ if (!callback_.is_null()) {
+ callback_.Run();
+ callback_.Reset();
+ }
+}
+
+void WebUIURLFetcherGroup::Start(
+ std::set<extensions::UserScript::File*> file_set,
+ int render_process_id,
+ int render_view_id) {
+ for (extensions::UserScript::File* file : file_set) {
+ scoped_ptr<WebUIURLFetcher> fetcher(new WebUIURLFetcher(
+ context_, base::Bind(&WebUIURLFetcherGroup::OnWebUIURLFetchComplete,
+ this, file)));
+ fetcher->Start(render_process_id, render_view_id, file->url());
+ fetchers_.push_back(fetcher.release());
+ }
+}
+
+void WebUIURLFetcherGroup::OnWebUIURLFetchComplete(
+ extensions::UserScript::File* script_file,
+ bool success,
+ const std::string& data) {
+ if (success) {
+ // Remove BOM from the content.
+ std::string::size_type index = data.find(base::kUtf8ByteOrderMark);
+ if (index == 0)
+ script_file->set_content(data.substr(strlen(base::kUtf8ByteOrderMark)));
+ else
+ script_file->set_content(data);
+ }
+
+ ++complete_fetchers_;
+ if (complete_fetchers_ == fetchers_.size()) {
+ callback_.Run();
+ callback_.Reset();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698