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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_event_router.cc

Issue 987583004: Add audible, muted to Tab, c.t.query, c.t.update, and c.t.onUpdated where relevant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch1
Patch Set: remove unneeded header files Created 5 years, 9 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: chrome/browser/extensions/api/tabs/tabs_event_router.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_event_router.cc b/chrome/browser/extensions/api/tabs/tabs_event_router.cc
index baab0e12ffeef2f666fae69c5454aeff8b6e8550..7c16af38a6b4f1a7d808f3cf8c071b0150f467e3 100644
--- a/chrome/browser/extensions/api/tabs/tabs_event_router.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_event_router.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/common/extensions/extension_constants.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_controller.h"
@@ -58,42 +59,67 @@ bool WillDispatchTabUpdatedEvent(
} // namespace
-TabsEventRouter::TabEntry::TabEntry() : complete_waiting_on_load_(false),
- url_() {
+TabsEventRouter::TabEntry::TabEntry()
+ : contents_(NULL),
+ complete_waiting_on_load_(false),
+ was_audible_(false),
+ was_muted_(false),
+ url_() {
not at google - send to devlin 2015/03/16 18:11:54 It's not necessary to initialize url()
}
-base::DictionaryValue* TabsEventRouter::TabEntry::UpdateLoadState(
- const WebContents* contents) {
+TabsEventRouter::TabEntry::TabEntry(content::WebContents* contents)
+ : contents_(contents),
+ complete_waiting_on_load_(false),
+ was_audible_(contents->WasRecentlyAudible()),
+ was_muted_(contents->IsAudioMuted()),
+ url_() {
+}
+
+DictionaryBuilder* TabsEventRouter::TabEntry::UpdateLoadState() {
// The tab may go in & out of loading (for instance if iframes navigate).
// We only want to respond to the first change from loading to !loading after
// the NAV_ENTRY_COMMITTED was fired.
- if (!complete_waiting_on_load_ || contents->IsLoading())
- return NULL;
+ if (!complete_waiting_on_load_ || contents_->IsLoading()) {
+ return new DictionaryBuilder();
+ }
// Send "complete" state change.
complete_waiting_on_load_ = false;
- base::DictionaryValue* changed_properties = new base::DictionaryValue();
- changed_properties->SetString(tabs_constants::kStatusKey,
- tabs_constants::kStatusValueComplete);
+ DictionaryBuilder* changed_properties = new DictionaryBuilder();
+ changed_properties->Set(tabs_constants::kStatusKey,
+ tabs_constants::kStatusValueComplete);
return changed_properties;
not at google - send to devlin 2015/03/16 18:11:55 Builder lets you do: return DictionaryValue()
}
-base::DictionaryValue* TabsEventRouter::TabEntry::DidNavigate(
- const WebContents* contents) {
+DictionaryBuilder* TabsEventRouter::TabEntry::DidNavigate() {
// Send "loading" state change.
complete_waiting_on_load_ = true;
- base::DictionaryValue* changed_properties = new base::DictionaryValue();
- changed_properties->SetString(tabs_constants::kStatusKey,
- tabs_constants::kStatusValueLoading);
+ DictionaryBuilder* changed_properties = new DictionaryBuilder();
+ changed_properties->Set(tabs_constants::kStatusKey,
+ tabs_constants::kStatusValueLoading);
- if (contents->GetURL() != url_) {
- url_ = contents->GetURL();
- changed_properties->SetString(tabs_constants::kUrlKey, url_.spec());
+ if (contents_->GetURL() != url_) {
+ url_ = contents_->GetURL();
+ changed_properties->Set(tabs_constants::kUrlKey, url_.spec());
}
return changed_properties;
}
+bool TabsEventRouter::TabEntry::SetAudible(bool new_val) {
+ if (was_audible_ == new_val)
+ return false;
+ was_audible_ = new_val;
+ return true;
+}
+
+bool TabsEventRouter::TabEntry::SetMuted(bool new_val) {
+ if (was_muted_ == new_val)
+ return false;
+ was_muted_ = new_val;
+ return true;
+}
+
TabsEventRouter::TabsEventRouter(Profile* profile) : profile_(profile) {
DCHECK(!profile->IsOffTheRecord());
@@ -110,7 +136,7 @@ TabsEventRouter::TabsEventRouter(Profile* profile) : profile_(profile) {
for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
WebContents* contents = browser->tab_strip_model()->GetWebContentsAt(i);
int tab_id = ExtensionTabUtil::GetTabId(contents);
- tab_entries_[tab_id] = TabEntry();
+ tab_entries_[tab_id] = TabEntry(contents);
}
}
}
@@ -215,7 +241,7 @@ void TabsEventRouter::TabInsertedAt(WebContents* contents,
// If tab is new, send created event.
int tab_id = ExtensionTabUtil::GetTabId(contents);
if (!GetTabEntry(contents)) {
- tab_entries_[tab_id] = TabEntry();
+ tab_entries_[tab_id] = TabEntry(contents);
TabCreatedAt(contents, index, active);
return;
@@ -390,19 +416,25 @@ void TabsEventRouter::TabMoved(WebContents* contents,
EventRouter::USER_GESTURE_UNKNOWN);
}
-void TabsEventRouter::TabUpdated(WebContents* contents, bool did_navigate) {
- TabEntry* entry = GetTabEntry(contents);
- scoped_ptr<base::DictionaryValue> changed_properties;
+void TabsEventRouter::TabUpdated(TabsEventRouter::TabEntry* entry,
+ DictionaryBuilder* changed_properties) {
not at google - send to devlin 2015/03/16 18:11:55 Yeah, I think that passing a DictionaryValue in he
+ CHECK(entry->contents_);
- CHECK(entry);
+ bool audible = entry->contents_->WasRecentlyAudible();
+ if (entry->SetAudible(audible)) {
+ changed_properties->SetBoolean(tabs_constants::kAudibleKey, audible);
+ }
- if (did_navigate)
- changed_properties.reset(entry->DidNavigate(contents));
- else
- changed_properties.reset(entry->UpdateLoadState(contents));
+ bool muted = entry->contents_->IsAudioMuted();
+ if (entry->SetMuted(muted)) {
+ changed_properties->SetBoolean(tabs_constants::kMutedKey, muted);
+ changed_properties->Set(tabs_constants::kMutedCauseKey,
+ chrome::GetTabAudioMutedCause(entry->contents_));
+ }
- if (changed_properties)
- DispatchTabUpdatedEvent(contents, changed_properties.Pass());
+ if (changed_properties->size() > 0) {
not at google - send to devlin 2015/03/16 18:11:55 use .empty() preferably.
+ DispatchTabUpdatedEvent(entry->contents_, changed_properties->Build());
+ }
}
void TabsEventRouter::FaviconUrlUpdated(WebContents* contents) {
@@ -493,7 +525,9 @@ void TabsEventRouter::Observe(int type,
if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
NavigationController* source_controller =
content::Source<NavigationController>(source).ptr();
- TabUpdated(source_controller->GetWebContents(), true);
+ TabEntry* entry = GetTabEntry(source_controller->GetWebContents());
+ CHECK(entry);
+ TabUpdated(entry, entry->DidNavigate());
} else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
// Tab was destroyed after being detached (without being re-attached).
WebContents* contents = content::Source<WebContents>(source).ptr();
@@ -515,7 +549,9 @@ void TabsEventRouter::Observe(int type,
void TabsEventRouter::TabChangedAt(WebContents* contents,
int index,
TabChangeType change_type) {
- TabUpdated(contents, false);
+ TabEntry* entry = GetTabEntry(contents);
+ CHECK(entry);
+ TabUpdated(entry, entry->UpdateLoadState());
}
void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
@@ -541,7 +577,7 @@ void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
UnregisterForTabNotifications(old_contents);
if (!GetTabEntry(new_contents)) {
- tab_entries_[new_tab_id] = TabEntry();
+ tab_entries_[new_tab_id] = TabEntry(new_contents);
RegisterForTabNotifications(new_contents);
}
}

Powered by Google App Engine
This is Rietveld 408576698