Add ICU message format support
[chromium-blink-merge.git] / ios / web / web_state / web_state_observer.cc
blob8e010657348ce5971ff1840a185995b192d19008
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
3 // found in the LICENSE file.
5 #include "ios/web/public/web_state/web_state_observer.h"
7 #include "ios/web/public/load_committed_details.h"
8 #include "ios/web/public/web_state/web_state.h"
10 namespace web {
12 int WebStateObserver::kInvalidFormKeyCode = -1;
14 WebStateObserver::WebStateObserver(WebState* web_state) : web_state_(nullptr) {
15 Observe(web_state);
18 WebStateObserver::WebStateObserver() : web_state_(nullptr) {
21 WebStateObserver::~WebStateObserver() {
22 if (web_state_)
23 web_state_->RemoveObserver(this);
26 void WebStateObserver::Observe(WebState* web_state) {
27 if (web_state == web_state_) {
28 // Early exit to avoid infinite loops if we're in the middle of a callback.
29 return;
31 if (web_state_)
32 web_state_->RemoveObserver(this);
33 web_state_ = web_state;
34 if (web_state_)
35 web_state_->AddObserver(this);
38 void WebStateObserver::ResetWebState() {
39 web_state_->RemoveObserver(this);
40 web_state_ = nullptr;
43 } // namespace web