File: frame_navigation_state.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (119 lines) | stat: -rw-r--r-- 4,576 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2012 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.

#ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_
#define CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_

#include <map>
#include <set>

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "url/gurl.h"

namespace content {
class RenderFrameHost;
}

namespace extensions {

// Tracks the loading state of all frame hosts in a given tab currently known
// to the webNavigation API. It is mainly used to track in which frames an error
// occurred so no further events for this frame are being sent.
class FrameNavigationState {
 public:
  typedef std::set<content::RenderFrameHost*>::const_iterator const_iterator;

  FrameNavigationState();
  ~FrameNavigationState();

  // True if in general webNavigation events may be sent for the given URL.
  static bool IsValidUrl(const GURL& url);

  // Use these to iterate over all frame hosts known by this object.
  const_iterator begin() const { return frame_hosts_.begin(); }
  const_iterator end() const { return frame_hosts_.end(); }

  // True if navigation events for the given frame can be sent.
  bool CanSendEvents(content::RenderFrameHost* frame_host) const;

  // Starts to track a document load in |frame_host| to |url|.
  void StartTrackingDocumentLoad(content::RenderFrameHost* frame_host,
                                 const GURL& url,
                                 bool is_same_page,
                                 bool is_error_page);

  // Adds the |frame_host| to the set of RenderFrameHosts associated with the
  // WebContents this object is tracking. This method and FrameHostDeleted
  // are used to track the set of current RenderFrameHosts, which is used to
  // implement the GetFrame and GetAllFrames extension APIs.
  void FrameHostCreated(content::RenderFrameHost* frame_host);

  // Removes the |frame_host| from the set of RenderFrameHosts associated with
  // the WebContents this object is tracking.
  void FrameHostDeleted(content::RenderFrameHost* frame_host);

  // Update the URL associated with |frame_host|.
  void UpdateFrame(content::RenderFrameHost* frame_host, const GURL& url);

  // Returns true if |frame_host| is a known frame host.
  bool IsValidFrame(content::RenderFrameHost* frame_host) const;

  // Returns the URL corresponding to a tracked |frame_host|.
  // TODO(dcheng): Why is this needed? Can't this information be extracted from
  // RenderFrameHost?
  GURL GetUrl(content::RenderFrameHost* frame_host) const;

  // Marks |frame_host| as in an error state, i.e. the onErrorOccurred event was
  // fired for it, and no further events should be sent for it.
  void SetErrorOccurredInFrame(content::RenderFrameHost* frame_host);

  // True if |frame_host| is marked as being in an error state.
  bool GetErrorOccurredInFrame(content::RenderFrameHost* frame_host) const;

  // Marks |frame_host| as having finished its last document load, i.e. the
  // onCompleted event was fired for this frame.
  void SetDocumentLoadCompleted(content::RenderFrameHost* frame_host);

  // True if |frame_host| is currently not loading a document.
  bool GetDocumentLoadCompleted(content::RenderFrameHost* frame_host) const;

  // Marks |frame_host| as having finished parsing.
  void SetParsingFinished(content::RenderFrameHost* frame_host);

  // True if |frame_host| has finished parsing.
  bool GetParsingFinished(content::RenderFrameHost* frame_host) const;

#ifdef UNIT_TEST
  static void set_allow_extension_scheme(bool allow_extension_scheme) {
    allow_extension_scheme_ = allow_extension_scheme;
  }
#endif

 private:
  struct FrameState {
    FrameState();

    bool error_occurred;  // True if an error has occurred in this frame.
    bool is_loading;        // True if there is a document load going on.
    bool is_parsing;  // True if the frame is still parsing.
    GURL url;  // URL of this frame.
  };
  typedef std::map<content::RenderFrameHost*, FrameState> FrameHostToStateMap;

  // Tracks the state of known frame hosts.
  FrameHostToStateMap frame_host_state_map_;

  // Set of all known frame hosts.
  std::set<content::RenderFrameHost*> frame_hosts_;

  // If true, also allow events from chrome-extension:// URLs.
  static bool allow_extension_scheme_;

  DISALLOW_COPY_AND_ASSIGN(FrameNavigationState);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_